
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.vasp.inputs &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.vasp.inputs</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.vasp.inputs</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Classes for reading/manipulating/writing VASP input files. All major VASP input</span>
<span class="sd">files.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">subprocess</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">numpy.linalg</span> <span class="kn">import</span> <span class="n">det</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span><span class="p">,</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">hashlib</span> <span class="kn">import</span> <span class="n">md5</span>

<span class="kn">from</span> <span class="nn">monty.io</span> <span class="kn">import</span> <span class="n">zopen</span>
<span class="kn">from</span> <span class="nn">monty.os.path</span> <span class="kn">import</span> <span class="n">zpath</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MontyDecoder</span>
<span class="kn">from</span> <span class="nn">monty.os</span> <span class="kn">import</span> <span class="n">cd</span>
<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span>

<span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>
<span class="kn">from</span> <span class="nn">tabulate</span> <span class="kn">import</span> <span class="n">tabulate</span>

<span class="kn">import</span> <span class="nn">scipy.constants</span> <span class="k">as</span> <span class="nn">const</span>

<span class="kn">from</span> <span class="nn">pymatgen</span> <span class="kn">import</span> <span class="n">SETTINGS</span><span class="p">,</span> <span class="n">__version__</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span><span class="p">,</span> <span class="n">get_el_sp</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Magmom</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.string</span> <span class="kn">import</span> <span class="n">str_delimited</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.io_utils</span> <span class="kn">import</span> <span class="n">clean_lines</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.typing</span> <span class="kn">import</span> <span class="n">PathLike</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong, Geoffroy Hautier, Rickard Armiento, Vincent L Chevrier, Stephen Dacek&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2011, The Materials Project&quot;</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="Poscar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar">[docs]</a><span class="k">class</span> <span class="nc">Poscar</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for representing the data in a POSCAR or CONTCAR file.</span>
<span class="sd">    Please note that this current implementation. Most attributes can be set</span>
<span class="sd">    directly.</span>

<span class="sd">    .. attribute:: structure</span>

<span class="sd">        Associated Structure.</span>

<span class="sd">    .. attribute:: comment</span>

<span class="sd">        Optional comment string.</span>

<span class="sd">    .. attribute:: true_names</span>

<span class="sd">        Boolean indication whether Poscar contains actual real names parsed</span>
<span class="sd">        from either a POTCAR or the POSCAR itself.</span>

<span class="sd">    .. attribute:: selective_dynamics</span>

<span class="sd">        Selective dynamics attribute for each site if available. A Nx3 array of</span>
<span class="sd">        booleans.</span>

<span class="sd">    .. attribute:: velocities</span>

<span class="sd">        Velocities for each site (typically read in from a CONTCAR). A Nx3</span>
<span class="sd">        array of floats.</span>

<span class="sd">    .. attribute:: predictor_corrector</span>

<span class="sd">        Predictor corrector coordinates and derivatives for each site; i.e.</span>
<span class="sd">        a list of three 1x3 arrays for each site (typically read in from a MD</span>
<span class="sd">        CONTCAR).</span>

<span class="sd">    .. attribute:: predictor_corrector_preamble</span>

<span class="sd">        Predictor corrector preamble contains the predictor-corrector key,</span>
<span class="sd">        POTIM, and thermostat parameters that precede the site-specic predictor</span>
<span class="sd">        corrector data in MD CONTCAR</span>

<span class="sd">    .. attribute:: temperature</span>

<span class="sd">        Temperature of velocity Maxwell-Boltzmann initialization. Initialized</span>
<span class="sd">        to -1 (MB hasn&quot;t been performed).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span>
        <span class="n">comment</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">selective_dynamics</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">true_names</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
        <span class="n">velocities</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">predictor_corrector</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">predictor_corrector_preamble</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">sort_structure</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        :param structure: Structure object.</span>
<span class="sd">        :param comment: Optional comment line for POSCAR. Defaults to unit</span>
<span class="sd">            cell formula of structure. Defaults to None.</span>
<span class="sd">        :param selective_dynamics: bool values for selective dynamics,</span>
<span class="sd">            where N is number of sites. Defaults to None.</span>
<span class="sd">        :param true_names: Set to False if the names in the POSCAR are not</span>
<span class="sd">            well-defined and ambiguous. This situation arises commonly in</span>
<span class="sd">            vasp &lt; 5 where the POSCAR sometimes does not contain element</span>
<span class="sd">            symbols. Defaults to True.</span>
<span class="sd">        :param velocities: Velocities for the POSCAR. Typically parsed</span>
<span class="sd">            in MD runs or can be used to initialize velocities.</span>
<span class="sd">        :param predictor_corrector: Predictor corrector for the POSCAR.</span>
<span class="sd">            Typically parsed in MD runs.</span>
<span class="sd">        :param predictor_corrector_preamble: Preamble to the predictor</span>
<span class="sd">            corrector.</span>
<span class="sd">        :param sort_structure: Whether to sort structure. Useful if species</span>
<span class="sd">            are not grouped properly together.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">structure</span><span class="o">.</span><span class="n">is_ordered</span><span class="p">:</span>
            <span class="n">site_properties</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">selective_dynamics</span><span class="p">:</span>
                <span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">selective_dynamics</span>
            <span class="k">if</span> <span class="n">velocities</span><span class="p">:</span>
                <span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">velocities</span>
            <span class="k">if</span> <span class="n">predictor_corrector</span><span class="p">:</span>
                <span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;predictor_corrector&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">predictor_corrector</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_sites</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">site_properties</span><span class="o">=</span><span class="n">site_properties</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">sort_structure</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">get_sorted_structure</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">true_names</span> <span class="o">=</span> <span class="n">true_names</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">formula</span> <span class="k">if</span> <span class="n">comment</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">comment</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector_preamble</span> <span class="o">=</span> <span class="n">predictor_corrector_preamble</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Structure with partial occupancies cannot be &quot;</span> <span class="s2">&quot;converted into POSCAR!&quot;</span>
            <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">velocities</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Velocities in Poscar&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;velocities&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">selective_dynamics</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Selective dynamics in Poscar&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">predictor_corrector</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Predictor corrector in Poscar&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;predictor_corrector&quot;</span><span class="p">)</span>

    <span class="nd">@velocities</span><span class="o">.</span><span class="n">setter</span>  <span class="c1"># type: ignore</span>
    <span class="k">def</span> <span class="nf">velocities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">velocities</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Setter for Poscar.velocities&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s2">&quot;velocities&quot;</span><span class="p">,</span> <span class="n">velocities</span><span class="p">)</span>

    <span class="nd">@selective_dynamics</span><span class="o">.</span><span class="n">setter</span>  <span class="c1"># type: ignore</span>
    <span class="k">def</span> <span class="nf">selective_dynamics</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">selective_dynamics</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Setter for Poscar.selective_dynamics&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">,</span> <span class="n">selective_dynamics</span><span class="p">)</span>

    <span class="nd">@predictor_corrector</span><span class="o">.</span><span class="n">setter</span>  <span class="c1"># type: ignore</span>
    <span class="k">def</span> <span class="nf">predictor_corrector</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">predictor_corrector</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Setter for Poscar.predictor_corrector&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s2">&quot;predictor_corrector&quot;</span><span class="p">,</span> <span class="n">predictor_corrector</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">site_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sequence of symbols associated with the Poscar. Similar to 6th line in</span>
<span class="sd">        vasp 5+ POSCAR.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">syms</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">syms</span><span class="p">)]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">natoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sequence of number of sites of each type associated with the Poscar.</span>
<span class="sd">        Similar to 7th line in vasp 5+ POSCAR or the 6th line in vasp 4 POSCAR.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">syms</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">syms</span><span class="p">)]</span>

    <span class="k">def</span> <span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">,</span> <span class="s2">&quot;velocities&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                <span class="n">dim</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">shape</span>
                <span class="k">if</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">3</span> <span class="ow">or</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="n">name</span> <span class="o">+</span> <span class="s2">&quot; array must be same length as&quot;</span> <span class="o">+</span> <span class="s2">&quot; the structure.&quot;</span>
                    <span class="p">)</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

<div class="viewcode-block" id="Poscar.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">check_for_POTCAR</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">read_velocities</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a Poscar from a file.</span>

<span class="sd">        The code will try its best to determine the elements in the POSCAR in</span>
<span class="sd">        the following order:</span>

<span class="sd">        1. If check_for_POTCAR is True, the code will try to check if a POTCAR</span>
<span class="sd">        is in the same directory as the POSCAR and use elements from that by</span>
<span class="sd">        default. (This is the VASP default sequence of priority).</span>
<span class="sd">        2. If the input file is Vasp5-like and contains element symbols in the</span>
<span class="sd">        6th line, the code will use that if check_for_POTCAR is False or there</span>
<span class="sd">        is no POTCAR found.</span>
<span class="sd">        3. Failing (2), the code will check if a symbol is provided at the end</span>
<span class="sd">        of each coordinate.</span>

<span class="sd">        If all else fails, the code will just assign the first n elements in</span>
<span class="sd">        increasing atomic number, where n is the number of species, to the</span>
<span class="sd">        Poscar. For example, H, He, Li, ....  This will ensure at least a</span>
<span class="sd">        unique element is assigned to each site and any analysis that does not</span>
<span class="sd">        require specific elemental properties should work fine.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): File name containing Poscar data.</span>
<span class="sd">            check_for_POTCAR (bool): Whether to check if a POTCAR is present</span>
<span class="sd">                in the same directory as the POSCAR. Defaults to True.</span>
<span class="sd">            read_velocities (bool): Whether to read or not velocities if they</span>
<span class="sd">                are present in the POSCAR. Default is True.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Poscar object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dirname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">filename</span><span class="p">))</span>
        <span class="n">names</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">check_for_POTCAR</span><span class="p">:</span>
            <span class="n">potcars</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span> <span class="s2">&quot;*POTCAR*&quot;</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">potcars</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">potcar</span> <span class="o">=</span> <span class="n">Potcar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">potcars</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
                    <span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="n">sym</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;_&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="n">potcar</span><span class="o">.</span><span class="n">symbols</span><span class="p">]</span>
                    <span class="p">[</span><span class="n">get_el_sp</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">names</span><span class="p">]</span>  <span class="c1"># ensure valid names</span>
                <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                    <span class="n">names</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">names</span><span class="p">,</span> <span class="n">read_velocities</span><span class="o">=</span><span class="n">read_velocities</span><span class="p">)</span></div>

<div class="viewcode-block" id="Poscar.from_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.from_string">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_string</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">default_names</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">read_velocities</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a Poscar from a string.</span>

<span class="sd">        The code will try its best to determine the elements in the POSCAR in</span>
<span class="sd">        the following order:</span>

<span class="sd">        1. If default_names are supplied and valid, it will use those. Usually,</span>
<span class="sd">        default names comes from an external source, such as a POTCAR in the</span>
<span class="sd">        same directory.</span>

<span class="sd">        2. If there are no valid default names but the input file is Vasp5-like</span>
<span class="sd">        and contains element symbols in the 6th line, the code will use that.</span>

<span class="sd">        3. Failing (2), the code will check if a symbol is provided at the end</span>
<span class="sd">        of each coordinate.</span>

<span class="sd">        If all else fails, the code will just assign the first n elements in</span>
<span class="sd">        increasing atomic number, where n is the number of species, to the</span>
<span class="sd">        Poscar. For example, H, He, Li, ....  This will ensure at least a</span>
<span class="sd">        unique element is assigned to each site and any analysis that does not</span>
<span class="sd">        require specific elemental properties should work fine.</span>

<span class="sd">        Args:</span>
<span class="sd">            data (str): String containing Poscar data.</span>
<span class="sd">            default_names ([str]): Default symbols for the POSCAR file,</span>
<span class="sd">                usually coming from a POTCAR in the same directory.</span>
<span class="sd">            read_velocities (bool): Whether to read or not velocities if they</span>
<span class="sd">                are present in the POSCAR. Default is True.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Poscar object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># &quot;^\s*$&quot; doesn&#39;t match lines with no whitespace</span>
        <span class="n">chunks</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\n\s*\n&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(),</span> <span class="n">flags</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">MULTILINE</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">chunks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                <span class="n">chunks</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                <span class="n">chunks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">chunks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Empty POSCAR&quot;</span><span class="p">)</span>

        <span class="c1"># Parse positions</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">clean_lines</span><span class="p">(</span><span class="n">chunks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">),</span> <span class="kc">False</span><span class="p">))</span>
        <span class="n">comment</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">lattice</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">5</span><span class="p">]])</span>
        <span class="k">if</span> <span class="n">scale</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># In vasp, a negative scale factor is treated as a volume. We need</span>
            <span class="c1"># to translate this to a proper lattice vector scaling.</span>
            <span class="n">vol</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">det</span><span class="p">(</span><span class="n">lattice</span><span class="p">))</span>
            <span class="n">lattice</span> <span class="o">*=</span> <span class="p">(</span><span class="o">-</span><span class="n">scale</span> <span class="o">/</span> <span class="n">vol</span><span class="p">)</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">lattice</span> <span class="o">*=</span> <span class="n">scale</span>

        <span class="n">vasp5_symbols</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">natoms</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
            <span class="n">ipos</span> <span class="o">=</span> <span class="mi">6</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="n">vasp5_symbols</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Atoms and number of atoms in POSCAR written with vasp appear on</span>
<span class="sd">            multiple lines when atoms of the same type are not grouped together</span>
<span class="sd">            and more than 20 groups are then defined ...</span>
<span class="sd">            Example :</span>
<span class="sd">            Cr16 Fe35 Ni2</span>
<span class="sd">               1.00000000000000</span>
<span class="sd">                 8.5415010000000002   -0.0077670000000000   -0.0007960000000000</span>
<span class="sd">                -0.0077730000000000    8.5224019999999996    0.0105580000000000</span>
<span class="sd">                -0.0007970000000000    0.0105720000000000    8.5356889999999996</span>
<span class="sd">               Fe   Cr   Fe   Cr   Fe   Cr   Fe   Cr   Fe   Cr   Fe   Cr   Fe   Cr   Fe   Ni   Fe   Cr   Fe   Cr</span>
<span class="sd">               Fe   Ni   Fe   Cr   Fe</span>
<span class="sd">                 1   1   2   4   2   1   1   1     2     1     1     1     4     1     1     1     5     3     6     1</span>
<span class="sd">                 2   1   3   2   5</span>
<span class="sd">            Direct</span>
<span class="sd">              ...</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">nlines_symbols</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">for</span> <span class="n">nlines_symbols</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">11</span><span class="p">):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="nb">int</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">5</span> <span class="o">+</span> <span class="n">nlines_symbols</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">])</span>
                    <span class="k">break</span>
                <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                    <span class="k">pass</span>
            <span class="k">for</span> <span class="n">iline_symbols</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">5</span> <span class="o">+</span> <span class="n">nlines_symbols</span><span class="p">):</span>
                <span class="n">symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="n">iline_symbols</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
            <span class="n">natoms</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">iline_natoms_start</span> <span class="o">=</span> <span class="mi">5</span> <span class="o">+</span> <span class="n">nlines_symbols</span>
            <span class="k">for</span> <span class="n">iline_natoms</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span>
                <span class="n">iline_natoms_start</span><span class="p">,</span> <span class="n">iline_natoms_start</span> <span class="o">+</span> <span class="n">nlines_symbols</span>
            <span class="p">):</span>
                <span class="n">natoms</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">iline_natoms</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>
            <span class="n">atomic_symbols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">natoms</span><span class="p">)):</span>
                <span class="n">atomic_symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">symbols</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">*</span> <span class="n">natoms</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="n">ipos</span> <span class="o">=</span> <span class="mi">5</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">nlines_symbols</span>

        <span class="n">postype</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">ipos</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">sdynamics</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="c1"># Selective dynamics</span>
        <span class="k">if</span> <span class="n">postype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="s2">&quot;sS&quot;</span><span class="p">:</span>
            <span class="n">sdynamics</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">ipos</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">postype</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">ipos</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">cart</span> <span class="o">=</span> <span class="n">postype</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="s2">&quot;cCkK&quot;</span>
        <span class="n">nsites</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">natoms</span><span class="p">)</span>

        <span class="c1"># If default_names is specified (usually coming from a POTCAR), use</span>
        <span class="c1"># them. This is in line with Vasp&quot;s parsing order that the POTCAR</span>
        <span class="c1"># specified is the default used.</span>
        <span class="k">if</span> <span class="n">default_names</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">atomic_symbols</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">natoms</span><span class="p">)):</span>
                    <span class="n">atomic_symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">default_names</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">*</span> <span class="n">natoms</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="n">vasp5_symbols</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                <span class="k">pass</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">vasp5_symbols</span><span class="p">:</span>
            <span class="n">ind</span> <span class="o">=</span> <span class="mi">3</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">sdynamics</span> <span class="k">else</span> <span class="mi">6</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># Check if names are appended at the end of the coordinates.</span>
                <span class="n">atomic_symbols</span> <span class="o">=</span> <span class="p">[</span>
                    <span class="n">l</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="n">ind</span><span class="p">]</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">ipos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">:</span> <span class="n">ipos</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">nsites</span><span class="p">]</span>
                <span class="p">]</span>
                <span class="c1"># Ensure symbols are valid elements</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">([</span><span class="n">Element</span><span class="o">.</span><span class="n">is_valid_symbol</span><span class="p">(</span><span class="n">sym</span><span class="p">)</span> <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="n">atomic_symbols</span><span class="p">]):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Non-valid symbols detected.&quot;</span><span class="p">)</span>
                <span class="n">vasp5_symbols</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span>
                <span class="c1"># Defaulting to false names.</span>
                <span class="n">atomic_symbols</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">natoms</span><span class="p">)):</span>
                    <span class="n">sym</span> <span class="o">=</span> <span class="n">Element</span><span class="o">.</span><span class="n">from_Z</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">symbol</span>
                    <span class="n">atomic_symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">sym</span><span class="p">]</span> <span class="o">*</span> <span class="n">natoms</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s2">&quot;Elements in POSCAR cannot be determined. &quot;</span>
                    <span class="s2">&quot;Defaulting to false names </span><span class="si">%s</span><span class="s2">.&quot;</span> <span class="o">%</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">atomic_symbols</span><span class="p">)</span>
                <span class="p">)</span>

        <span class="c1"># read the atomic coordinates</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">selective_dynamics</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span> <span class="k">if</span> <span class="n">sdynamics</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nsites</span><span class="p">):</span>
            <span class="n">toks</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">ipos</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="n">crd_scale</span> <span class="o">=</span> <span class="n">scale</span> <span class="k">if</span> <span class="n">cart</span> <span class="k">else</span> <span class="mi">1</span>
            <span class="n">coords</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">j</span><span class="p">)</span> <span class="o">*</span> <span class="n">crd_scale</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[:</span><span class="mi">3</span><span class="p">]])</span>
            <span class="k">if</span> <span class="n">sdynamics</span><span class="p">:</span>
                <span class="n">selective_dynamics</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">tok</span><span class="o">.</span><span class="n">upper</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;T&quot;</span> <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">6</span><span class="p">]])</span>

        <span class="n">struct</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span>
            <span class="n">lattice</span><span class="p">,</span>
            <span class="n">atomic_symbols</span><span class="p">,</span>
            <span class="n">coords</span><span class="p">,</span>
            <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">validate_proximity</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="n">cart</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="k">if</span> <span class="n">read_velocities</span><span class="p">:</span>
            <span class="c1"># Parse velocities if any</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">chunks</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">chunks</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span>
                    <span class="n">velocities</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">)</span> <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>

            <span class="c1"># Parse the predictor-corrector data</span>
            <span class="n">predictor_corrector</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">predictor_corrector_preamble</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">chunks</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">lines</span> <span class="o">=</span> <span class="n">chunks</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="c1"># There are 3 sets of 3xN Predictor corrector parameters</span>
                <span class="c1"># So can&#39;t be stored as a single set of &quot;site_property&quot;</span>

                <span class="c1"># First line in chunk is a key in CONTCAR</span>
                <span class="c1"># Second line is POTIM</span>
                <span class="c1"># Third line is the thermostat parameters</span>
                <span class="n">predictor_corrector_preamble</span> <span class="o">=</span> <span class="p">(</span>
                    <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                <span class="p">)</span>
                <span class="c1"># Rest is three sets of parameters, each set contains</span>
                <span class="c1"># x, y, z predictor-corrector parameters for every atom in orde</span>
                <span class="n">lines</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">:]</span>
                <span class="k">for</span> <span class="n">st</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nsites</span><span class="p">):</span>
                    <span class="n">d1</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">)</span> <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">st</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                    <span class="n">d2</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">)</span> <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">st</span> <span class="o">+</span> <span class="n">nsites</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                    <span class="n">d3</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">)</span> <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">st</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">nsites</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                    <span class="n">predictor_corrector</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">d1</span><span class="p">,</span> <span class="n">d2</span><span class="p">,</span> <span class="n">d3</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">predictor_corrector</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">predictor_corrector_preamble</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">Poscar</span><span class="p">(</span>
            <span class="n">struct</span><span class="p">,</span>
            <span class="n">comment</span><span class="p">,</span>
            <span class="n">selective_dynamics</span><span class="p">,</span>
            <span class="n">vasp5_symbols</span><span class="p">,</span>
            <span class="n">velocities</span><span class="o">=</span><span class="n">velocities</span><span class="p">,</span>
            <span class="n">predictor_corrector</span><span class="o">=</span><span class="n">predictor_corrector</span><span class="p">,</span>
            <span class="n">predictor_corrector_preamble</span><span class="o">=</span><span class="n">predictor_corrector_preamble</span><span class="p">,</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Poscar.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">direct</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">vasp4_compatible</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">significant_figures</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string to be written as a POSCAR file. By default, site</span>
<span class="sd">        symbols are written, which means compatibility is for vasp &gt;= 5.</span>

<span class="sd">        Args:</span>
<span class="sd">            direct (bool): Whether coordinates are output in direct or</span>
<span class="sd">                cartesian. Defaults to True.</span>
<span class="sd">            vasp4_compatible (bool): Set to True to omit site symbols on 6th</span>
<span class="sd">                line to maintain backward vasp 4.x compatibility. Defaults</span>
<span class="sd">                to False.</span>
<span class="sd">            significant_figures (int): No. of significant figures to</span>
<span class="sd">                output all quantities. Defaults to 6. Note that positions are</span>
<span class="sd">                output in fixed point, while velocities are output in</span>
<span class="sd">                scientific format.</span>

<span class="sd">        Returns:</span>
<span class="sd">            String representation of POSCAR.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># This corrects for VASP really annoying bug of crashing on lattices</span>
        <span class="c1"># which have triple product &lt; 0. We will just invert the lattice</span>
        <span class="c1"># vectors.</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">det</span><span class="p">(</span><span class="n">latt</span><span class="o">.</span><span class="n">matrix</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">latt</span> <span class="o">=</span> <span class="n">Lattice</span><span class="p">(</span><span class="o">-</span><span class="n">latt</span><span class="o">.</span><span class="n">matrix</span><span class="p">)</span>

        <span class="n">format_str</span> <span class="o">=</span> <span class="s2">&quot;{{:.</span><span class="si">{0}</span><span class="s2">f}}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">significant_figures</span><span class="p">)</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span> <span class="s2">&quot;1.0&quot;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">latt</span><span class="o">.</span><span class="n">matrix</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">true_names</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">vasp4_compatible</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site_symbols</span><span class="p">))</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">natoms</span><span class="p">]))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">selective_dynamics</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Selective dynamics&quot;</span><span class="p">)</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;direct&quot;</span> <span class="k">if</span> <span class="n">direct</span> <span class="k">else</span> <span class="s2">&quot;cartesian&quot;</span><span class="p">)</span>

        <span class="n">selective_dynamics</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">selective_dynamics</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">site</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">):</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">if</span> <span class="n">direct</span> <span class="k">else</span> <span class="n">site</span><span class="o">.</span><span class="n">coords</span>
            <span class="n">line</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">selective_dynamics</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">sd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;T&quot;</span> <span class="k">if</span> <span class="n">j</span> <span class="k">else</span> <span class="s2">&quot;F&quot;</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">selective_dynamics</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span>
                <span class="n">line</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">sd</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">sd</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">sd</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="n">line</span> <span class="o">+=</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">site</span><span class="o">.</span><span class="n">species_string</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="p">:</span>
                    <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]))</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Velocities are missing or corrupted.&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector_preamble</span><span class="p">:</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector_preamble</span><span class="p">)</span>
                <span class="n">pred</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">pred</span><span class="p">[:,</span> <span class="n">col</span><span class="p">]:</span>
                        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">z</span><span class="p">]))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s2">&quot;Preamble information missing or corrupt. &quot;</span>
                    <span class="s2">&quot;Writing Poscar with no predictor corrector data.&quot;</span>
                <span class="p">)</span>

        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span></div>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        String representation of Poscar file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

<div class="viewcode-block" id="Poscar.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes POSCAR to a file. The supported kwargs are the same as those for</span>
<span class="sd">        the Poscar.get_string method and are passed through directly.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">))</span></div>

<div class="viewcode-block" id="Poscar.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
            <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
            <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
            <span class="s2">&quot;true_names&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">true_names</span><span class="p">,</span>
            <span class="s2">&quot;selective_dynamics&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">selective_dynamics</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span>
            <span class="s2">&quot;velocities&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="p">,</span>
            <span class="s2">&quot;predictor_corrector&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">predictor_corrector</span><span class="p">,</span>
            <span class="s2">&quot;comment&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span>
        <span class="p">}</span></div>

<div class="viewcode-block" id="Poscar.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param d: Dict representation.</span>
<span class="sd">        :return: Poscar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Poscar</span><span class="p">(</span>
            <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]),</span>
            <span class="n">comment</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">],</span>
            <span class="n">selective_dynamics</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">],</span>
            <span class="n">true_names</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;true_names&quot;</span><span class="p">],</span>
            <span class="n">velocities</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;velocities&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
            <span class="n">predictor_corrector</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;predictor_corrector&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Poscar.set_temperature"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Poscar.set_temperature">[docs]</a>    <span class="k">def</span> <span class="nf">set_temperature</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">temperature</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes the velocities based on Maxwell-Boltzmann distribution.</span>
<span class="sd">        Removes linear, but not angular drift (same as VASP)</span>

<span class="sd">        Scales the energies to the exact temperature (microcanonical ensemble)</span>
<span class="sd">        Velocities are given in A/fs. This is the vasp default when</span>
<span class="sd">        direct/cartesian is not specified (even when positions are given in</span>
<span class="sd">        direct coordinates)</span>

<span class="sd">        Overwrites imported velocities, if any.</span>

<span class="sd">        Args:</span>
<span class="sd">            temperature (float): Temperature in Kelvin.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># mean 0 variance 1</span>
        <span class="n">velocities</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>

        <span class="c1"># in AMU, (N,1) array</span>
        <span class="n">atomic_masses</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">atomic_mass</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="s2">&quot;kg&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">]</span>
        <span class="p">)</span>
        <span class="n">dof</span> <span class="o">=</span> <span class="mi">3</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span> <span class="o">-</span> <span class="mi">3</span>

        <span class="c1"># scale velocities due to atomic masses</span>
        <span class="c1"># mean 0 std proportional to sqrt(1/m)</span>
        <span class="n">velocities</span> <span class="o">/=</span> <span class="n">atomic_masses</span><span class="p">[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>

        <span class="c1"># remove linear drift (net momentum)</span>
        <span class="n">velocities</span> <span class="o">-=</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">(</span>
            <span class="n">atomic_masses</span><span class="p">[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span> <span class="o">*</span> <span class="n">velocities</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span>
        <span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">average</span><span class="p">(</span><span class="n">atomic_masses</span><span class="p">)</span>

        <span class="c1"># scale velocities to get correct temperature</span>
        <span class="n">energy</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">atomic_masses</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">velocities</span> <span class="o">**</span> <span class="mi">2</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="p">(</span><span class="n">temperature</span> <span class="o">*</span> <span class="n">dof</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">energy</span> <span class="o">/</span> <span class="n">const</span><span class="o">.</span><span class="n">k</span><span class="p">))</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>

        <span class="n">velocities</span> <span class="o">*=</span> <span class="n">scale</span> <span class="o">*</span> <span class="mf">1e-5</span>  <span class="c1"># these are in A/fs</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="n">temperature</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;selective_dynamics&quot;</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;predictor_corrector&quot;</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="c1"># returns as a list of lists to be consistent with the other</span>
        <span class="c1"># initializations</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s2">&quot;velocities&quot;</span><span class="p">,</span> <span class="n">velocities</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span></div></div>


<span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s2">&quot;incar_parameters.json&quot;</span><span class="p">))</span> <span class="k">as</span> <span class="n">incar_params</span><span class="p">:</span>
    <span class="n">incar_params</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">incar_params</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>


<div class="viewcode-block" id="BadIncarWarning"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.BadIncarWarning">[docs]</a><span class="k">class</span> <span class="nc">BadIncarWarning</span><span class="p">(</span><span class="ne">UserWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Warning class for bad Incar parameters.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">pass</span></div>


<div class="viewcode-block" id="Incar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar">[docs]</a><span class="k">class</span> <span class="nc">Incar</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    INCAR object for reading and writing INCAR files. Essentially consists of</span>
<span class="sd">    a dictionary with some helper functions</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Creates an Incar object.</span>

<span class="sd">        Args:</span>
<span class="sd">            params (dict): A set of input parameters as a dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">params</span><span class="p">:</span>

            <span class="c1"># if Incar contains vector-like magmoms given as a list</span>
            <span class="c1"># of floats, convert to a list of lists</span>
            <span class="k">if</span> <span class="p">(</span>
                <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">))</span>
            <span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LSORBIT&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LNONCOLLINEAR&quot;</span><span class="p">)):</span>
                <span class="n">val</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">])</span> <span class="o">//</span> <span class="mi">3</span><span class="p">):</span>
                    <span class="n">val</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">][</span><span class="n">i</span> <span class="o">*</span> <span class="mi">3</span><span class="p">:</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">3</span><span class="p">])</span>
                <span class="n">params</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">params</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add parameter-val pair to Incar.  Warns if parameter is not in list of</span>
<span class="sd">        valid INCAR tags. Also cleans the parameter and val by stripping</span>
<span class="sd">        leading and trailing white spaces.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setitem__</span><span class="p">(</span>
            <span class="n">key</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span>
            <span class="n">Incar</span><span class="o">.</span><span class="n">proc_val</span><span class="p">(</span><span class="n">key</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span> <span class="n">val</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">val</span><span class="p">,</span>
        <span class="p">)</span>

<div class="viewcode-block" id="Incar.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="Incar.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param d: Dict representation.</span>
<span class="sd">        :return: Incar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">Magmom</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;MAGMOM&quot;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="n">Incar</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;@module&quot;</span><span class="p">,</span> <span class="s2">&quot;@class&quot;</span><span class="p">)})</span></div>

<div class="viewcode-block" id="Incar.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sort_keys</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string representation of the INCAR.  The reason why this</span>
<span class="sd">        method is different from the __str__ method is to provide options for</span>
<span class="sd">        pretty printing.</span>

<span class="sd">        Args:</span>
<span class="sd">            sort_keys (bool): Set to True to sort the INCAR parameters</span>
<span class="sd">                alphabetically. Defaults to False.</span>
<span class="sd">            pretty (bool): Set to True for pretty aligned output. Defaults</span>
<span class="sd">                to False.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">keys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">sort_keys</span><span class="p">:</span>
            <span class="n">keys</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">keys</span><span class="p">)</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="s2">&quot;MAGMOM&quot;</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">value</span> <span class="o">=</span> <span class="p">[]</span>

                <span class="k">if</span> <span class="p">(</span>
                    <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="nb">list</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">Magmom</span><span class="p">)</span>
                <span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LSORBIT&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LNONCOLLINEAR&quot;</span><span class="p">)):</span>
                    <span class="n">value</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">j</span><span class="p">))</span>
                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LSORBIT&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LNONCOLLINEAR&quot;</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">m</span><span class="p">,</span> <span class="n">g</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]):</span>
                        <span class="n">value</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;3*</span><span class="si">{}</span><span class="s2">*</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">g</span><span class="p">)),</span> <span class="n">m</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="c1"># float() to ensure backwards compatibility between</span>
                    <span class="c1"># float magmoms and Magmom objects</span>
                    <span class="k">for</span> <span class="n">m</span><span class="p">,</span> <span class="n">g</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)):</span>
                        <span class="n">value</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">*</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">g</span><span class="p">)),</span> <span class="n">m</span><span class="p">))</span>

                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">value</span><span class="p">)])</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]])])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]])</span>

        <span class="k">if</span> <span class="n">pretty</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">tabulate</span><span class="p">([[</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;=&quot;</span><span class="p">,</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">],</span> <span class="n">tablefmt</span><span class="o">=</span><span class="s2">&quot;plain&quot;</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">str_delimited</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot; = &quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="n">sort_keys</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">pretty</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

<div class="viewcode-block" id="Incar.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write Incar to a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): filename to write to.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">())</span></div>

<div class="viewcode-block" id="Incar.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads an Incar object from a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename for file</span>

<span class="sd">        Returns:</span>
<span class="sd">            Incar object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Incar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></div>

<div class="viewcode-block" id="Incar.from_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.from_string">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_string</span><span class="p">(</span><span class="n">string</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads an Incar object from a string.</span>

<span class="sd">        Args:</span>
<span class="sd">            string (str): Incar string</span>

<span class="sd">        Returns:</span>
<span class="sd">            Incar object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">clean_lines</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()))</span>
        <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">sline</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;;&quot;</span><span class="p">):</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(\w+)\s*=\s*(.*)&quot;</span><span class="p">,</span> <span class="n">sline</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="n">key</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                    <span class="n">val</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                    <span class="n">val</span> <span class="o">=</span> <span class="n">Incar</span><span class="o">.</span><span class="n">proc_val</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
                    <span class="n">params</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
        <span class="k">return</span> <span class="n">Incar</span><span class="p">(</span><span class="n">params</span><span class="p">)</span></div>

<div class="viewcode-block" id="Incar.proc_val"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.proc_val">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">proc_val</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Static helper method to convert INCAR parameters to proper types, e.g.,</span>
<span class="sd">        integers, floats, lists, etc.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: INCAR parameter key</span>
<span class="sd">            val: Actual value of INCAR parameter.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">list_keys</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s2">&quot;LDAUU&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LDAUL&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LDAUJ&quot;</span><span class="p">,</span>
            <span class="s2">&quot;MAGMOM&quot;</span><span class="p">,</span>
            <span class="s2">&quot;DIPOL&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LANGEVIN_GAMMA&quot;</span><span class="p">,</span>
            <span class="s2">&quot;QUAD_EFG&quot;</span><span class="p">,</span>
            <span class="s2">&quot;EINT&quot;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">bool_keys</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s2">&quot;LDAU&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LWAVE&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LSCALU&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LCHARG&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LPLANE&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LUSE_VDW&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LHFCALC&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ADDGRID&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LSORBIT&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LNONCOLLINEAR&quot;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">float_keys</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s2">&quot;EDIFF&quot;</span><span class="p">,</span>
            <span class="s2">&quot;SIGMA&quot;</span><span class="p">,</span>
            <span class="s2">&quot;TIME&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ENCUTFOCK&quot;</span><span class="p">,</span>
            <span class="s2">&quot;HFSCREEN&quot;</span><span class="p">,</span>
            <span class="s2">&quot;POTIM&quot;</span><span class="p">,</span>
            <span class="s2">&quot;EDIFFG&quot;</span><span class="p">,</span>
            <span class="s2">&quot;AGGAC&quot;</span><span class="p">,</span>
            <span class="s2">&quot;PARAM1&quot;</span><span class="p">,</span>
            <span class="s2">&quot;PARAM2&quot;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">int_keys</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s2">&quot;NSW&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NBANDS&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NELMIN&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ISIF&quot;</span><span class="p">,</span>
            <span class="s2">&quot;IBRION&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ISPIN&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ICHARG&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NELM&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ISMEAR&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NPAR&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LDAUPRINT&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LMAXMIX&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ENCUT&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NSIM&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NKRED&quot;</span><span class="p">,</span>
            <span class="s2">&quot;NUPDOWN&quot;</span><span class="p">,</span>
            <span class="s2">&quot;ISPIND&quot;</span><span class="p">,</span>
            <span class="s2">&quot;LDAUTYPE&quot;</span><span class="p">,</span>
            <span class="s2">&quot;IVDW&quot;</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="k">def</span> <span class="nf">smart_int_or_float</span><span class="p">(</span><span class="n">numstr</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">numstr</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span> <span class="ow">or</span> <span class="n">numstr</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;e&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">numstr</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">numstr</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">list_keys</span><span class="p">:</span>
                <span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">toks</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span>
                    <span class="sa">r</span><span class="s2">&quot;(-?\d+\.?\d*)\*?(-?\d+\.?\d*)?\*?(-?\d+\.?\d*)?&quot;</span><span class="p">,</span> <span class="n">val</span>
                <span class="p">)</span>
                <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">tok</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="ow">and</span> <span class="s2">&quot;3&quot;</span> <span class="ow">in</span> <span class="n">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
                        <span class="n">output</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
                            <span class="p">[</span><span class="n">smart_int_or_float</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span> <span class="o">*</span> <span class="nb">int</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="nb">int</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                        <span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                        <span class="n">output</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">smart_int_or_float</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">])]</span> <span class="o">*</span> <span class="nb">int</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">smart_int_or_float</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
                <span class="k">return</span> <span class="n">output</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">bool_keys</span><span class="p">:</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^\.?([T|F|t|f])[A-Za-z]*\.?&quot;</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;T&quot;</span> <span class="ow">or</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;t&quot;</span><span class="p">:</span>
                        <span class="k">return</span> <span class="kc">True</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">return</span> <span class="kc">False</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; should be a boolean type!&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">float_keys</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^-?\d*\.?\d*[e|E]?-?\d*&quot;</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">int_keys</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^-?[0-9]+&quot;</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>

        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="c1"># Not in standard keys. We will try a hierarchy of conversions.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">val</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">val</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">val</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">val</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">if</span> <span class="s2">&quot;true&quot;</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span>
            <span class="k">return</span> <span class="kc">True</span>

        <span class="k">if</span> <span class="s2">&quot;false&quot;</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="k">return</span> <span class="n">val</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span></div>

<div class="viewcode-block" id="Incar.diff"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.diff">[docs]</a>    <span class="k">def</span> <span class="nf">diff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Diff function for Incar.  Compares two Incars and indicates which</span>
<span class="sd">        parameters are the same and which are not. Useful for checking whether</span>
<span class="sd">        two runs were done using the same parameters.</span>

<span class="sd">        Args:</span>
<span class="sd">            other (Incar): The other Incar object to compare to.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dict of the following format:</span>
<span class="sd">            {&quot;Same&quot; : parameters_that_are_the_same,</span>
<span class="sd">            &quot;Different&quot;: parameters_that_are_different}</span>
<span class="sd">            Note that the parameters are return as full dictionaries of values.</span>
<span class="sd">            E.g. {&quot;ISIF&quot;:3}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">similar_param</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">different_param</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k1</span><span class="p">,</span> <span class="n">v1</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">k1</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">other</span><span class="p">:</span>
                <span class="n">different_param</span><span class="p">[</span><span class="n">k1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;INCAR1&quot;</span><span class="p">:</span> <span class="n">v1</span><span class="p">,</span> <span class="s2">&quot;INCAR2&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>
            <span class="k">elif</span> <span class="n">v1</span> <span class="o">!=</span> <span class="n">other</span><span class="p">[</span><span class="n">k1</span><span class="p">]:</span>
                <span class="n">different_param</span><span class="p">[</span><span class="n">k1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;INCAR1&quot;</span><span class="p">:</span> <span class="n">v1</span><span class="p">,</span> <span class="s2">&quot;INCAR2&quot;</span><span class="p">:</span> <span class="n">other</span><span class="p">[</span><span class="n">k1</span><span class="p">]}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">similar_param</span><span class="p">[</span><span class="n">k1</span><span class="p">]</span> <span class="o">=</span> <span class="n">v1</span>
        <span class="k">for</span> <span class="n">k2</span><span class="p">,</span> <span class="n">v2</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">k2</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">similar_param</span> <span class="ow">and</span> <span class="n">k2</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">different_param</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">k2</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
                    <span class="n">different_param</span><span class="p">[</span><span class="n">k2</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;INCAR1&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;INCAR2&quot;</span><span class="p">:</span> <span class="n">v2</span><span class="p">}</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;Same&quot;</span><span class="p">:</span> <span class="n">similar_param</span><span class="p">,</span> <span class="s2">&quot;Different&quot;</span><span class="p">:</span> <span class="n">different_param</span><span class="p">}</span></div>

    <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add all the values of another INCAR object to this object.</span>
<span class="sd">        Facilitates the use of &quot;standard&quot; INCARs.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">other</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span> <span class="ow">and</span> <span class="n">v</span> <span class="o">!=</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Incars have conflicting values!&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">params</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
        <span class="k">return</span> <span class="n">Incar</span><span class="p">(</span><span class="n">params</span><span class="p">)</span>

<div class="viewcode-block" id="Incar.check_params"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Incar.check_params">[docs]</a>    <span class="k">def</span> <span class="nf">check_params</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Raises a warning for nonsensical or non-existant INCAR tags and</span>
<span class="sd">        parameters. If a keyword doesn&#39;t exist (e.g. theres a typo in a</span>
<span class="sd">        keyword), your calculation will still run, however VASP will igore the</span>
<span class="sd">        parameter without letting you know, hence why we have this Incar method.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>

            <span class="c1"># First check if this parameter even exists</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">incar_params</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s2">&quot;Cannot find </span><span class="si">%s</span><span class="s2"> in the list of INCAR flags&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">),</span>
                    <span class="n">BadIncarWarning</span><span class="p">,</span>
                    <span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                <span class="p">)</span>

            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">incar_params</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;str&quot;</span><span class="p">:</span>
                    <span class="c1"># Now we check if this is an appropriate parameter type</span>
                    <span class="k">if</span> <span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;float&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">]:</span>
                            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                                <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2"> is not real&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]),</span>
                                <span class="n">BadIncarWarning</span><span class="p">,</span>
                                <span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                            <span class="p">)</span>
                    <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">]:</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                            <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2"> is not a </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">]),</span>
                            <span class="n">BadIncarWarning</span><span class="p">,</span>
                            <span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                        <span class="p">)</span>

                <span class="c1"># if we have a list of possible parameters, check</span>
                <span class="c1"># if the user given parameter is in this list</span>
                <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;list&quot;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">incar_params</span><span class="p">[</span><span class="n">k</span><span class="p">]:</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                            <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: Cannot find </span><span class="si">%s</span><span class="s2"> in the list of parameters&quot;</span>
                            <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]),</span>
                            <span class="n">BadIncarWarning</span><span class="p">,</span>
                            <span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                        <span class="p">)</span></div></div>


<div class="viewcode-block" id="Kpoints_supported_modes"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints_supported_modes">[docs]</a><span class="k">class</span> <span class="nc">Kpoints_supported_modes</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Enum type of all supported modes for Kpoint generation.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">Automatic</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">Gamma</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="n">Monkhorst</span> <span class="o">=</span> <span class="mi">2</span>
    <span class="n">Line_mode</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="n">Cartesian</span> <span class="o">=</span> <span class="mi">4</span>
    <span class="n">Reciprocal</span> <span class="o">=</span> <span class="mi">5</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>

<div class="viewcode-block" id="Kpoints_supported_modes.from_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints_supported_modes.from_string">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_string</span><span class="p">(</span><span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="s2">&quot;Kpoints_supported_modes&quot;</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param s: String</span>
<span class="sd">        :return: Kpoints_supported_modes</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">Kpoints_supported_modes</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">c</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">m</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Can&#39;t interprete Kpoint mode </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">s</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Kpoints"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints">[docs]</a><span class="k">class</span> <span class="nc">Kpoints</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    KPOINT reader/writer.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">supported_modes</span> <span class="o">=</span> <span class="n">Kpoints_supported_modes</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;Default gamma&quot;</span><span class="p">,</span>
        <span class="n">num_kpts</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
        <span class="n">style</span><span class="o">=</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Gamma</span><span class="p">,</span>
        <span class="n">kpts</span><span class="o">=</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),),</span>
        <span class="n">kpts_shift</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
        <span class="n">kpts_weights</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">coord_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">labels</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">tet_number</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
        <span class="n">tet_weight</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
        <span class="n">tet_connections</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Highly flexible constructor for Kpoints object.  The flexibility comes</span>
<span class="sd">        at the cost of usability and in general, it is recommended that you use</span>
<span class="sd">        the default constructor only if you know exactly what you are doing and</span>
<span class="sd">        requires the flexibility.  For most usage cases, the three automatic</span>
<span class="sd">        schemes can be constructed far more easily using the convenience static</span>
<span class="sd">        constructors (automatic, gamma_automatic, monkhorst_automatic) and it</span>
<span class="sd">        is recommended that you use those.</span>

<span class="sd">        Args:</span>
<span class="sd">            comment (str): String comment for Kpoints</span>
<span class="sd">            num_kpts: Following VASP method of defining the KPOINTS file, this</span>
<span class="sd">                parameter is the number of kpoints specified. If set to 0</span>
<span class="sd">                (or negative), VASP automatically generates the KPOINTS.</span>
<span class="sd">            style: Style for generating KPOINTS.  Use one of the</span>
<span class="sd">                Kpoints.supported_modes enum types.</span>
<span class="sd">            kpts (2D array): 2D array of kpoints.  Even when only a single</span>
<span class="sd">                specification is required, e.g. in the automatic scheme,</span>
<span class="sd">                the kpts should still be specified as a 2D array. e.g.,</span>
<span class="sd">                [[20]] or [[2,2,2]].</span>
<span class="sd">            kpts_shift (3x1 array): Shift for Kpoints.</span>
<span class="sd">            kpts_weights: Optional weights for kpoints.  Weights should be</span>
<span class="sd">                integers. For explicit kpoints.</span>
<span class="sd">            coord_type: In line-mode, this variable specifies whether the</span>
<span class="sd">                Kpoints were given in Cartesian or Reciprocal coordinates.</span>
<span class="sd">            labels: In line-mode, this should provide a list of labels for</span>
<span class="sd">                each kpt. It is optional in explicit kpoint mode as comments for</span>
<span class="sd">                k-points.</span>
<span class="sd">            tet_number: For explicit kpoints, specifies the number of</span>
<span class="sd">                tetrahedrons for the tetrahedron method.</span>
<span class="sd">            tet_weight: For explicit kpoints, specifies the weight for each</span>
<span class="sd">                tetrahedron for the tetrahedron method.</span>
<span class="sd">            tet_connections: For explicit kpoints, specifies the connections</span>
<span class="sd">                of the tetrahedrons for the tetrahedron method.</span>
<span class="sd">                Format is a list of tuples, [ (sym_weight, [tet_vertices]),</span>
<span class="sd">                ...]</span>

<span class="sd">        The default behavior of the constructor is for a Gamma centered,</span>
<span class="sd">        1x1x1 KPOINTS with no shift.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">num_kpts</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="n">labels</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="n">kpts_weights</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;For explicit or line-mode kpoints, either the &quot;</span>
                <span class="s2">&quot;labels or kpts_weights must be specified.&quot;</span>
            <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">comment</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span> <span class="o">=</span> <span class="n">num_kpts</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpts</span> <span class="o">=</span> <span class="n">kpts</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">style</span> <span class="o">=</span> <span class="n">style</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">coord_type</span> <span class="o">=</span> <span class="n">coord_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span> <span class="o">=</span> <span class="n">kpts_weights</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kpts_shift</span> <span class="o">=</span> <span class="n">kpts_shift</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tet_number</span> <span class="o">=</span> <span class="n">tet_number</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tet_weight</span> <span class="o">=</span> <span class="n">tet_weight</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tet_connections</span> <span class="o">=</span> <span class="n">tet_connections</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">style</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Style for kpoint generation. One of Kpoints_supported_modes</span>
<span class="sd">            enum.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_style</span>

    <span class="nd">@style</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">style</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param style: Style</span>
<span class="sd">        :return: Sets the style for the Kpoints. One of Kpoints_supported_modes</span>
<span class="sd">            enum.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">style</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">style</span><span class="p">)</span>

        <span class="k">if</span> <span class="p">(</span>
            <span class="n">style</span>
            <span class="ow">in</span> <span class="p">(</span>
                <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Automatic</span><span class="p">,</span>
                <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Gamma</span><span class="p">,</span>
                <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Monkhorst</span><span class="p">,</span>
            <span class="p">)</span>
            <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span>
        <span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;For fully automatic or automatic gamma or monk &quot;</span>
                <span class="s2">&quot;kpoints, only a single line for the number of &quot;</span>
                <span class="s2">&quot;divisions is allowed.&quot;</span>
            <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_style</span> <span class="o">=</span> <span class="n">style</span>

<div class="viewcode-block" id="Kpoints.automatic"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.automatic">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">automatic</span><span class="p">(</span><span class="n">subdivisions</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for a fully automatic Kpoint grid, with</span>
<span class="sd">        gamma centered Monkhorst-Pack grids and the number of subdivisions</span>
<span class="sd">        along each reciprocal lattice vector determined by the scheme in the</span>
<span class="sd">        VASP manual.</span>

<span class="sd">        Args:</span>
<span class="sd">            subdivisions: Parameter determining number of subdivisions along</span>
<span class="sd">                each reciprocal lattice vector.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
            <span class="s2">&quot;Fully automatic kpoint scheme&quot;</span><span class="p">,</span>
            <span class="mi">0</span><span class="p">,</span>
            <span class="n">style</span><span class="o">=</span><span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Automatic</span><span class="p">,</span>
            <span class="n">kpts</span><span class="o">=</span><span class="p">[[</span><span class="n">subdivisions</span><span class="p">]],</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.gamma_automatic"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.gamma_automatic">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">gamma_automatic</span><span class="p">(</span><span class="n">kpts</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">shift</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for an automatic Gamma centered Kpoint</span>
<span class="sd">        grid.</span>

<span class="sd">        Args:</span>
<span class="sd">            kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice</span>
<span class="sd">                vectors. Defaults to (1,1,1)</span>
<span class="sd">            shift: Shift to be applied to the kpoints. Defaults to (0,0,0).</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
            <span class="s2">&quot;Automatic kpoint scheme&quot;</span><span class="p">,</span>
            <span class="mi">0</span><span class="p">,</span>
            <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Gamma</span><span class="p">,</span>
            <span class="n">kpts</span><span class="o">=</span><span class="p">[</span><span class="n">kpts</span><span class="p">],</span>
            <span class="n">kpts_shift</span><span class="o">=</span><span class="n">shift</span><span class="p">,</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.monkhorst_automatic"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.monkhorst_automatic">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">monkhorst_automatic</span><span class="p">(</span><span class="n">kpts</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">shift</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for an automatic Monkhorst pack Kpoint</span>
<span class="sd">        grid.</span>

<span class="sd">        Args:</span>
<span class="sd">            kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice</span>
<span class="sd">                vectors. Defaults to (2,2,2)</span>
<span class="sd">            shift: Shift to be applied to the kpoints. Defaults to (0,0,0).</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
            <span class="s2">&quot;Automatic kpoint scheme&quot;</span><span class="p">,</span>
            <span class="mi">0</span><span class="p">,</span>
            <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Monkhorst</span><span class="p">,</span>
            <span class="n">kpts</span><span class="o">=</span><span class="p">[</span><span class="n">kpts</span><span class="p">],</span>
            <span class="n">kpts_shift</span><span class="o">=</span><span class="n">shift</span><span class="p">,</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.automatic_density"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.automatic_density">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">automatic_density</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">kppa</span><span class="p">,</span> <span class="n">force_gamma</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an automatic Kpoint object based on a structure and a kpoint</span>
<span class="sd">        density. Uses Gamma centered meshes for hexagonal cells and</span>
<span class="sd">        Monkhorst-Pack grids otherwise.</span>

<span class="sd">        Algorithm:</span>
<span class="sd">            Uses a simple approach scaling the number of divisions along each</span>
<span class="sd">            reciprocal lattice vector proportional to its length.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): Input structure</span>
<span class="sd">            kppa (int): Grid density</span>
<span class="sd">            force_gamma (bool): Force a gamma centered mesh (default is to</span>
<span class="sd">                use gamma only for hexagonal cells or odd meshes)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">comment</span> <span class="o">=</span> <span class="s2">&quot;pymatgen v</span><span class="si">%s</span><span class="s2"> with grid density = </span><span class="si">%.0f</span><span class="s2"> / number of atoms&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">__version__</span><span class="p">,</span> <span class="n">kppa</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">((</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">kppa</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.5</span><span class="p">))</span> <span class="o">**</span> <span class="mi">3</span> <span class="o">-</span> <span class="n">kppa</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">kppa</span> <span class="o">+=</span> <span class="n">kppa</span> <span class="o">*</span> <span class="mf">0.01</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
        <span class="n">lengths</span> <span class="o">=</span> <span class="n">latt</span><span class="o">.</span><span class="n">abc</span>
        <span class="n">ngrid</span> <span class="o">=</span> <span class="n">kppa</span> <span class="o">/</span> <span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span>
        <span class="n">mult</span> <span class="o">=</span> <span class="p">(</span><span class="n">ngrid</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>

        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">mult</span> <span class="o">/</span> <span class="n">l</span><span class="p">,</span> <span class="mi">1</span><span class="p">)))</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">lengths</span><span class="p">]</span>

        <span class="n">is_hexagonal</span> <span class="o">=</span> <span class="n">latt</span><span class="o">.</span><span class="n">is_hexagonal</span><span class="p">()</span>

        <span class="n">has_odd</span> <span class="o">=</span> <span class="nb">any</span><span class="p">([</span><span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">num_div</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">has_odd</span> <span class="ow">or</span> <span class="n">is_hexagonal</span> <span class="ow">or</span> <span class="n">force_gamma</span><span class="p">:</span>
            <span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Gamma</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Monkhorst</span>

        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span><span class="n">comment</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="p">[</span><span class="n">num_div</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div>

<div class="viewcode-block" id="Kpoints.automatic_gamma_density"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.automatic_gamma_density">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">automatic_gamma_density</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">kppa</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an automatic Kpoint object based on a structure and a kpoint</span>
<span class="sd">        density. Uses Gamma centered meshes always. For GW.</span>

<span class="sd">        Algorithm:</span>
<span class="sd">            Uses a simple approach scaling the number of divisions along each</span>
<span class="sd">            reciprocal lattice vector proportional to its length.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure:</span>
<span class="sd">                Input structure</span>
<span class="sd">            kppa:</span>
<span class="sd">                Grid density</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">latt</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span>
        <span class="n">lengths</span> <span class="o">=</span> <span class="n">latt</span><span class="o">.</span><span class="n">abc</span>
        <span class="n">ngrid</span> <span class="o">=</span> <span class="n">kppa</span> <span class="o">/</span> <span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span>

        <span class="n">mult</span> <span class="o">=</span> <span class="p">(</span><span class="n">ngrid</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">mult</span> <span class="o">/</span> <span class="n">l</span><span class="p">))</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">lengths</span><span class="p">]</span>

        <span class="c1"># ensure that numDiv[i] &gt; 0</span>
        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">num_div</span><span class="p">]</span>

        <span class="c1"># VASP documentation recommends to use even grids for n &lt;= 8 and odd</span>
        <span class="c1"># grids for n &gt; 8.</span>
        <span class="n">num_div</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="k">if</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="mi">8</span> <span class="k">else</span> <span class="n">i</span> <span class="o">-</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">num_div</span><span class="p">]</span>

        <span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Gamma</span>

        <span class="n">comment</span> <span class="o">=</span> <span class="s2">&quot;pymatgen v</span><span class="si">%s</span><span class="s2"> with grid density = </span><span class="si">%.0f</span><span class="s2"> / number of atoms&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">__version__</span><span class="p">,</span> <span class="n">kppa</span><span class="p">)</span>

        <span class="n">num_kpts</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span><span class="n">comment</span><span class="p">,</span> <span class="n">num_kpts</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="p">[</span><span class="n">num_div</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div>

<div class="viewcode-block" id="Kpoints.automatic_density_by_vol"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.automatic_density_by_vol">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">automatic_density_by_vol</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">kppvol</span><span class="p">,</span> <span class="n">force_gamma</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an automatic Kpoint object based on a structure and a kpoint</span>
<span class="sd">        density per inverse Angstrom^3 of reciprocal cell.</span>

<span class="sd">        Algorithm:</span>
<span class="sd">            Same as automatic_density()</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): Input structure</span>
<span class="sd">            kppvol (int): Grid density per Angstrom^(-3) of reciprocal cell</span>
<span class="sd">            force_gamma (bool): Force a gamma centered mesh</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">vol</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="o">.</span><span class="n">volume</span>
        <span class="n">kppa</span> <span class="o">=</span> <span class="n">kppvol</span> <span class="o">*</span> <span class="n">vol</span> <span class="o">*</span> <span class="n">structure</span><span class="o">.</span><span class="n">num_sites</span>
        <span class="k">return</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">automatic_density</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">kppa</span><span class="p">,</span> <span class="n">force_gamma</span><span class="o">=</span><span class="n">force_gamma</span><span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.automatic_linemode"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.automatic_linemode">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">automatic_linemode</span><span class="p">(</span><span class="n">divisions</span><span class="p">,</span> <span class="n">ibz</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenient static constructor for a KPOINTS in mode line_mode.</span>
<span class="sd">        gamma centered Monkhorst-Pack grids and the number of subdivisions</span>
<span class="sd">        along each reciprocal lattice vector determined by the scheme in the</span>
<span class="sd">        VASP manual.</span>

<span class="sd">        Args:</span>
<span class="sd">            divisions: Parameter determining the number of k-points along each</span>
<span class="sd">                hight symetry lines.</span>
<span class="sd">            ibz: HighSymmKpath object (pymatgen.symmetry.bandstructure)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">kpoints</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">ibz</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;path&quot;</span><span class="p">]:</span>
            <span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ibz</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="n">path</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span>
            <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
                <span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ibz</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="n">path</span><span class="p">[</span><span class="n">i</span><span class="p">]])</span>
                <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ibz</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="n">path</span><span class="p">[</span><span class="n">i</span><span class="p">]])</span>
                <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

            <span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ibz</span><span class="o">.</span><span class="n">kpath</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="n">path</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
            <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
            <span class="s2">&quot;Line_mode KPOINTS file&quot;</span><span class="p">,</span>
            <span class="n">style</span><span class="o">=</span><span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Line_mode</span><span class="p">,</span>
            <span class="n">coord_type</span><span class="o">=</span><span class="s2">&quot;Reciprocal&quot;</span><span class="p">,</span>
            <span class="n">kpts</span><span class="o">=</span><span class="n">kpoints</span><span class="p">,</span>
            <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span>
            <span class="n">num_kpts</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">divisions</span><span class="p">),</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a Kpoints object from a KPOINTS file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): filename to read from.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></div>

<div class="viewcode-block" id="Kpoints.from_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.from_string">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_string</span><span class="p">(</span><span class="n">string</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a Kpoints object from a KPOINTS string.</span>

<span class="sd">        Args:</span>
<span class="sd">            string (str): KPOINTS string.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Kpoints object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">string</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()]</span>

        <span class="n">comment</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">num_kpts</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
        <span class="n">style</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Fully automatic KPOINTS</span>
        <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;a&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">automatic</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>

        <span class="n">coord_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;^\s*([\d+.\-Ee]+)\s+([\d+.\-Ee]+)\s+&quot;</span> <span class="sa">r</span><span class="s2">&quot;([\d+.\-Ee]+)&quot;</span>
        <span class="p">)</span>

        <span class="c1"># Automatic gamma and Monk KPOINTS, with optional shift</span>
        <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;g&quot;</span> <span class="ow">or</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;m&quot;</span><span class="p">:</span>
            <span class="n">kpts</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
            <span class="n">kpts_shift</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4</span> <span class="ow">and</span> <span class="n">coord_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">]):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">kpts_shift</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                    <span class="k">pass</span>
            <span class="k">return</span> <span class="p">(</span>
                <span class="n">Kpoints</span><span class="o">.</span><span class="n">gamma_automatic</span><span class="p">(</span><span class="n">kpts</span><span class="p">,</span> <span class="n">kpts_shift</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;g&quot;</span>
                <span class="k">else</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">monkhorst_automatic</span><span class="p">(</span><span class="n">kpts</span><span class="p">,</span> <span class="n">kpts_shift</span><span class="p">)</span>
            <span class="p">)</span>

        <span class="c1"># Automatic kpoints with basis</span>
        <span class="k">if</span> <span class="n">num_kpts</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">style</span> <span class="o">=</span> <span class="p">(</span>
                <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Cartesian</span>
                <span class="k">if</span> <span class="n">style</span> <span class="ow">in</span> <span class="s2">&quot;ck&quot;</span>
                <span class="k">else</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Reciprocal</span>
            <span class="p">)</span>
            <span class="n">kpts</span> <span class="o">=</span> <span class="p">[[</span><span class="nb">float</span><span class="p">(</span><span class="n">j</span><span class="p">)</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">)]</span>
            <span class="n">kpts_shift</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
            <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
                <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">,</span>
                <span class="n">num_kpts</span><span class="o">=</span><span class="n">num_kpts</span><span class="p">,</span>
                <span class="n">style</span><span class="o">=</span><span class="n">style</span><span class="p">,</span>
                <span class="n">kpts</span><span class="o">=</span><span class="n">kpts</span><span class="p">,</span>
                <span class="n">kpts_shift</span><span class="o">=</span><span class="n">kpts_shift</span><span class="p">,</span>
            <span class="p">)</span>

        <span class="c1"># Line-mode KPOINTS, usually used with band structures</span>
        <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span>
            <span class="n">coord_type</span> <span class="o">=</span> <span class="s2">&quot;Cartesian&quot;</span> <span class="k">if</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="s2">&quot;ck&quot;</span> <span class="k">else</span> <span class="s2">&quot;Reciprocal&quot;</span>
            <span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Line_mode</span>
            <span class="n">kpts</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">labels</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">patt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
                <span class="sa">r</span><span class="s2">&quot;([e0-9.\-]+)\s+([e0-9.\-]+)\s+([e0-9.\-]+)&quot;</span> <span class="sa">r</span><span class="s2">&quot;\s*!*\s*(.*)&quot;</span>
            <span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">lines</span><span class="p">)):</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">patt</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="n">kpts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))]</span>
                    <span class="p">)</span>
                    <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
            <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
                <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">,</span>
                <span class="n">num_kpts</span><span class="o">=</span><span class="n">num_kpts</span><span class="p">,</span>
                <span class="n">style</span><span class="o">=</span><span class="n">style</span><span class="p">,</span>
                <span class="n">kpts</span><span class="o">=</span><span class="n">kpts</span><span class="p">,</span>
                <span class="n">coord_type</span><span class="o">=</span><span class="n">coord_type</span><span class="p">,</span>
                <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span>
            <span class="p">)</span>

        <span class="c1"># Assume explicit KPOINTS if all else fails.</span>
        <span class="n">style</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Cartesian</span>
            <span class="k">if</span> <span class="n">style</span> <span class="ow">in</span> <span class="s2">&quot;ck&quot;</span>
            <span class="k">else</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Reciprocal</span>
        <span class="p">)</span>
        <span class="n">kpts</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">kpts_weights</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">labels</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">tet_number</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">tet_weight</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">tet_connections</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span> <span class="o">+</span> <span class="n">num_kpts</span><span class="p">):</span>
            <span class="n">toks</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="n">kpts</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">j</span><span class="p">)</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">]])</span>
            <span class="n">kpts_weights</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4</span><span class="p">:</span>
                <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">labels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Deal with tetrahedron method</span>
            <span class="k">if</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span> <span class="o">+</span> <span class="n">num_kpts</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;t&quot;</span><span class="p">:</span>
                <span class="n">toks</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">4</span> <span class="o">+</span> <span class="n">num_kpts</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="n">tet_number</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">tet_weight</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">tet_connections</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span> <span class="o">+</span> <span class="n">num_kpts</span><span class="p">,</span> <span class="mi">5</span> <span class="o">+</span> <span class="n">num_kpts</span> <span class="o">+</span> <span class="n">tet_number</span><span class="p">):</span>
                    <span class="n">toks</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">tet_connections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="n">j</span><span class="p">])</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">)])</span>
                    <span class="p">)</span>
        <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">return</span> <span class="n">Kpoints</span><span class="p">(</span>
            <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">,</span>
            <span class="n">num_kpts</span><span class="o">=</span><span class="n">num_kpts</span><span class="p">,</span>
            <span class="n">style</span><span class="o">=</span><span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">style</span><span class="p">)],</span>
            <span class="n">kpts</span><span class="o">=</span><span class="n">kpts</span><span class="p">,</span>
            <span class="n">kpts_weights</span><span class="o">=</span><span class="n">kpts_weights</span><span class="p">,</span>
            <span class="n">tet_number</span><span class="o">=</span><span class="n">tet_number</span><span class="p">,</span>
            <span class="n">tet_weight</span><span class="o">=</span><span class="n">tet_weight</span><span class="p">,</span>
            <span class="n">tet_connections</span><span class="o">=</span><span class="n">tet_connections</span><span class="p">,</span>
            <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">,</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="Kpoints.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write Kpoints to a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename to write to.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">())</span></div>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
        <span class="n">style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">coord_type</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts</span><span class="p">)):</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts</span><span class="p">[</span><span class="n">i</span><span class="p">]]))</span>
            <span class="k">if</span> <span class="n">style</span> <span class="o">==</span> <span class="s2">&quot;l&quot;</span><span class="p">:</span>
                <span class="n">lines</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s2">&quot; ! &quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">lines</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">lines</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%i</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">lines</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%i</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

        <span class="c1"># Print tetrahedron parameters if the number of tetrahedrons &gt; 0</span>
        <span class="k">if</span> <span class="n">style</span> <span class="ow">not</span> <span class="ow">in</span> <span class="s2">&quot;lagm&quot;</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_number</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Tetrahedron&quot;</span><span class="p">)</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%d</span><span class="s2"> </span><span class="si">%f</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tet_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_weight</span><span class="p">))</span>
            <span class="k">for</span> <span class="n">sym_weight</span><span class="p">,</span> <span class="n">vertices</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_connections</span><span class="p">:</span>
                <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="s2">&quot;</span><span class="si">%d</span><span class="s2"> </span><span class="si">%d</span><span class="s2"> </span><span class="si">%d</span><span class="s2"> </span><span class="si">%d</span><span class="s2"> </span><span class="si">%d</span><span class="s2">&quot;</span>
                    <span class="o">%</span> <span class="p">(</span><span class="n">sym_weight</span><span class="p">,</span> <span class="n">vertices</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">vertices</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">vertices</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">vertices</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                <span class="p">)</span>

        <span class="c1"># Print shifts for automatic kpoints types if not zero.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span> <span class="o">&lt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpts_shift</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts_shift</span><span class="p">]))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>

<div class="viewcode-block" id="Kpoints.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;comment&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span>
            <span class="s2">&quot;nkpoints&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_kpts</span><span class="p">,</span>
            <span class="s2">&quot;generation_style&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
            <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts</span><span class="p">,</span>
            <span class="s2">&quot;usershift&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts_shift</span><span class="p">,</span>
            <span class="s2">&quot;kpts_weights&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpts_weights</span><span class="p">,</span>
            <span class="s2">&quot;coord_type&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">coord_type</span><span class="p">,</span>
            <span class="s2">&quot;labels&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">,</span>
            <span class="s2">&quot;tet_number&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_number</span><span class="p">,</span>
            <span class="s2">&quot;tet_weight&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_weight</span><span class="p">,</span>
            <span class="s2">&quot;tet_connections&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">tet_connections</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="n">optional_paras</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;genvec1&quot;</span><span class="p">,</span> <span class="s2">&quot;genvec2&quot;</span><span class="p">,</span> <span class="s2">&quot;genvec3&quot;</span><span class="p">,</span> <span class="s2">&quot;shift&quot;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">para</span> <span class="ow">in</span> <span class="n">optional_paras</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">para</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">:</span>
                <span class="n">d</span><span class="p">[</span><span class="n">para</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">para</span><span class="p">]</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="Kpoints.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Kpoints.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param d: Dict representation.</span>
<span class="sd">        :return: Kpoints</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">comment</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;comment&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="n">generation_style</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;generation_style&quot;</span><span class="p">)</span>
        <span class="n">kpts</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;kpoints&quot;</span><span class="p">,</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
        <span class="n">kpts_shift</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;usershift&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">num_kpts</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nkpoints&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span>
            <span class="n">comment</span><span class="o">=</span><span class="n">comment</span><span class="p">,</span>
            <span class="n">kpts</span><span class="o">=</span><span class="n">kpts</span><span class="p">,</span>
            <span class="n">style</span><span class="o">=</span><span class="n">generation_style</span><span class="p">,</span>
            <span class="n">kpts_shift</span><span class="o">=</span><span class="n">kpts_shift</span><span class="p">,</span>
            <span class="n">num_kpts</span><span class="o">=</span><span class="n">num_kpts</span><span class="p">,</span>
            <span class="n">kpts_weights</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;kpts_weights&quot;</span><span class="p">),</span>
            <span class="n">coord_type</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;coord_type&quot;</span><span class="p">),</span>
            <span class="n">labels</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;labels&quot;</span><span class="p">),</span>
            <span class="n">tet_number</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;tet_number&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
            <span class="n">tet_weight</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;tet_weight&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
            <span class="n">tet_connections</span><span class="o">=</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;tet_connections&quot;</span><span class="p">),</span>
        <span class="p">)</span></div></div>


<span class="k">def</span> <span class="nf">_parse_string</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="k">return</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>


<span class="k">def</span> <span class="nf">_parse_bool</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^\.?([TFtf])[A-Za-z]*\.?&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;T&quot;</span> <span class="ow">or</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;t&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">s</span> <span class="o">+</span> <span class="s2">&quot; should be a boolean type!&quot;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_parse_float</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^-?\d*\.?\d*[eE]?-?\d*&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">_parse_int</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^-?[0-9]+&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">_parse_list</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">y</span><span class="o">.</span><span class="n">isalpha</span><span class="p">()]</span>


<span class="n">Orbital</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;Orbital&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">,</span> <span class="s2">&quot;l&quot;</span><span class="p">,</span> <span class="s2">&quot;j&quot;</span><span class="p">,</span> <span class="s2">&quot;E&quot;</span><span class="p">,</span> <span class="s2">&quot;occ&quot;</span><span class="p">])</span>
<span class="n">OrbitalDescription</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span>
    <span class="s2">&quot;OrbitalDescription&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;l&quot;</span><span class="p">,</span> <span class="s2">&quot;E&quot;</span><span class="p">,</span> <span class="s2">&quot;Type&quot;</span><span class="p">,</span> <span class="s2">&quot;Rcut&quot;</span><span class="p">,</span> <span class="s2">&quot;Type2&quot;</span><span class="p">,</span> <span class="s2">&quot;Rcut2&quot;</span><span class="p">]</span>
<span class="p">)</span>


<div class="viewcode-block" id="UnknownPotcarWarning"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.UnknownPotcarWarning">[docs]</a><span class="k">class</span> <span class="nc">UnknownPotcarWarning</span><span class="p">(</span><span class="ne">UserWarning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Warning raised when POTCAR hashes do not pass validation</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">pass</span></div>


<div class="viewcode-block" id="PotcarSingle"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle">[docs]</a><span class="k">class</span> <span class="nc">PotcarSingle</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for a **single** POTCAR. The builder assumes the POTCAR contains</span>
<span class="sd">    the complete untouched data in &quot;data&quot; as a string and a dict of keywords.</span>

<span class="sd">    .. attribute:: data</span>

<span class="sd">        POTCAR data as a string.</span>

<span class="sd">    .. attribute:: keywords</span>

<span class="sd">        Keywords parsed from the POTCAR as a dict. All keywords are also</span>
<span class="sd">        accessible as attributes in themselves. E.g., potcar.enmax,</span>
<span class="sd">        potcar.encut, etc.</span>

<span class="sd">    md5 hashes of the entire POTCAR file and the actual data are validated</span>
<span class="sd">    against a database of known good hashes. Appropriate warnings or errors</span>
<span class="sd">    are raised if a POTCAR hash fails validation.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">functional_dir</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;PBE&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE&quot;</span><span class="p">,</span>
        <span class="s2">&quot;PBE_52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;PBE_54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PBE_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;LDA&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW&quot;</span><span class="p">,</span>
        <span class="s2">&quot;LDA_52&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_52&quot;</span><span class="p">,</span>
        <span class="s2">&quot;LDA_54&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW_54&quot;</span><span class="p">,</span>
        <span class="s2">&quot;PW91&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_PAW_PW91&quot;</span><span class="p">,</span>
        <span class="s2">&quot;LDA_US&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_US&quot;</span><span class="p">,</span>
        <span class="s2">&quot;PW91_US&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_GGA_US_PW91&quot;</span><span class="p">,</span>
        <span class="s2">&quot;Perdew-Zunger81&quot;</span><span class="p">:</span> <span class="s2">&quot;POT_LDA_PAW&quot;</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="n">functional_tags</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;pe&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;91&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;PW91&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;rp&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;revPBE&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;am&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;AM05&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;ps&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;PBEsol&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;pw&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;PW86&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;lm&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Langreth-Mehl-Hu&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;pb&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Perdew-Becke&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;ca&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Perdew-Zunger81&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;hl&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Hedin-Lundquist&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA&quot;</span><span class="p">},</span>
        <span class="s2">&quot;wi&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Wigner Interpoloation&quot;</span><span class="p">,</span> <span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA&quot;</span><span class="p">},</span>
    <span class="p">}</span>

    <span class="n">parse_functions</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">&quot;LULTRA&quot;</span><span class="p">:</span> <span class="n">_parse_bool</span><span class="p">,</span>
        <span class="s2">&quot;LUNSCR&quot;</span><span class="p">:</span> <span class="n">_parse_bool</span><span class="p">,</span>
        <span class="s2">&quot;LCOR&quot;</span><span class="p">:</span> <span class="n">_parse_bool</span><span class="p">,</span>
        <span class="s2">&quot;LPAW&quot;</span><span class="p">:</span> <span class="n">_parse_bool</span><span class="p">,</span>
        <span class="s2">&quot;EATOM&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RPACOR&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;POMASS&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;ZVAL&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RCORE&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RWIGS&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;ENMAX&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;ENMIN&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;EMMIN&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;EAUG&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;DEXC&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RMAX&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RAUG&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RDEP&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RDEPT&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;QCUT&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;QGAM&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;RCLOC&quot;</span><span class="p">:</span> <span class="n">_parse_float</span><span class="p">,</span>
        <span class="s2">&quot;IUNSCR&quot;</span><span class="p">:</span> <span class="n">_parse_int</span><span class="p">,</span>
        <span class="s2">&quot;ICORE&quot;</span><span class="p">:</span> <span class="n">_parse_int</span><span class="p">,</span>
        <span class="s2">&quot;NDATA&quot;</span><span class="p">:</span> <span class="n">_parse_int</span><span class="p">,</span>
        <span class="s2">&quot;VRHFIN&quot;</span><span class="p">:</span> <span class="n">_parse_string</span><span class="p">,</span>
        <span class="s2">&quot;LEXCH&quot;</span><span class="p">:</span> <span class="n">_parse_string</span><span class="p">,</span>
        <span class="s2">&quot;TITEL&quot;</span><span class="p">:</span> <span class="n">_parse_string</span><span class="p">,</span>
        <span class="s2">&quot;STEP&quot;</span><span class="p">:</span> <span class="n">_parse_list</span><span class="p">,</span>
        <span class="s2">&quot;RRKJ&quot;</span><span class="p">:</span> <span class="n">_parse_list</span><span class="p">,</span>
        <span class="s2">&quot;GGA&quot;</span><span class="p">:</span> <span class="n">_parse_list</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">symbol</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            data:</span>
<span class="sd">                Complete and single potcar file as a string.</span>
<span class="sd">            symbol:</span>
<span class="sd">                POTCAR symbol corresponding to the filename suffix</span>
<span class="sd">                e.g. &quot;Tm_3&quot; for POTCAR.TM_3&quot;. If not given, pymatgen</span>
<span class="sd">                will attempt to extract the symbol from the file itself.</span>
<span class="sd">                However, this is not always reliable!</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>  <span class="c1"># raw POTCAR as a string</span>

        <span class="c1"># Vasp parses header in vasprun.xml and this differs from the titel</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

        <span class="n">search_lines</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;(?s)(parameters from PSCTR are:&quot;</span> <span class="sa">r</span><span class="s2">&quot;.*?END of PSCTR-controll parameters)&quot;</span><span class="p">,</span>
            <span class="n">data</span><span class="p">,</span>
        <span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;(\S+)\s*=\s*(.*?)(?=;|$)&quot;</span><span class="p">,</span> <span class="n">search_lines</span><span class="p">,</span> <span class="n">flags</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">MULTILINE</span>
        <span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_functions</span><span class="p">[</span><span class="n">key</span><span class="p">](</span><span class="n">val</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Ignoring unknown variable type </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>

        <span class="n">PSCTR</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>

        <span class="n">array_search</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(-*[0-9.]+)&quot;</span><span class="p">)</span>
        <span class="n">orbitals</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">descriptions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">atomic_configuration</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;Atomic configuration\s*\n?&quot;</span> <span class="sa">r</span><span class="s2">&quot;(.*?)Description&quot;</span><span class="p">,</span> <span class="n">search_lines</span>
        <span class="p">)</span>
        <span class="k">if</span> <span class="n">atomic_configuration</span><span class="p">:</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="n">atomic_configuration</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
            <span class="n">num_entries</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;([0-9]+)&quot;</span><span class="p">,</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">num_entries</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">num_entries</span><span class="p">)</span>
            <span class="n">PSCTR</span><span class="p">[</span><span class="s2">&quot;nentries&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">num_entries</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
                <span class="n">orbit</span> <span class="o">=</span> <span class="n">array_search</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">orbit</span><span class="p">:</span>
                    <span class="n">orbitals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">Orbital</span><span class="p">(</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">orbit</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">orbit</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">orbit</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">orbit</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">orbit</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span>
                        <span class="p">)</span>
                    <span class="p">)</span>
            <span class="n">PSCTR</span><span class="p">[</span><span class="s2">&quot;Orbitals&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">orbitals</span><span class="p">)</span>

        <span class="n">description_string</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;(?s)Description\s*\n&quot;</span>
            <span class="sa">r</span><span class="s2">&quot;(.*?)Error from kinetic&quot;</span>
            <span class="sa">r</span><span class="s2">&quot; energy argument \(eV\)&quot;</span><span class="p">,</span>
            <span class="n">search_lines</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="k">if</span> <span class="n">description_string</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">description_string</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">():</span>
                <span class="n">description</span> <span class="o">=</span> <span class="n">array_search</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">description</span><span class="p">:</span>
                    <span class="n">descriptions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="n">OrbitalDescription</span><span class="p">(</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
                            <span class="nb">int</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">description</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                            <span class="nb">float</span><span class="p">(</span><span class="n">description</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">description</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                        <span class="p">)</span>
                    <span class="p">)</span>

        <span class="k">if</span> <span class="n">descriptions</span><span class="p">:</span>
            <span class="n">PSCTR</span><span class="p">[</span><span class="s2">&quot;OrbitalDescriptions&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">descriptions</span><span class="p">)</span>

        <span class="n">rrkj_kinetic_energy_string</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span>
            <span class="sa">r</span><span class="s2">&quot;(?s)Error from kinetic energy argument \(eV\)\s*\n&quot;</span>
            <span class="sa">r</span><span class="s2">&quot;(.*?)END of PSCTR-controll parameters&quot;</span><span class="p">,</span>
            <span class="n">search_lines</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">rrkj_array</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">rrkj_kinetic_energy_string</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">rrkj_kinetic_energy_string</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">():</span>
                <span class="k">if</span> <span class="s2">&quot;=&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">rrkj_array</span> <span class="o">+=</span> <span class="n">_parse_list</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">rrkj_array</span><span class="p">:</span>
                <span class="n">PSCTR</span><span class="p">[</span><span class="s2">&quot;RRKJ&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">rrkj_array</span><span class="p">)</span>

        <span class="n">PSCTR</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">PSCTR</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">PSCTR</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>

        <span class="k">if</span> <span class="n">symbol</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_symbol</span> <span class="o">=</span> <span class="n">symbol</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_symbol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">[</span><span class="s2">&quot;TITEL&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_symbol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">[</span><span class="s2">&quot;TITEL&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>

        <span class="c1"># Compute the POTCAR hashes and check them against the database of known</span>
        <span class="c1"># VASP POTCARs</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">hash</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_potcar_hash</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">file_hash</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_potcar_file_hash</span><span class="p">()</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">identify_potcar</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;data&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="p">[]:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;POTCAR data with symbol </span><span class="si">{}</span><span class="s2"> does not match any VASP</span><span class="se">\</span>
<span class="s2">                          POTCAR known to pymatgen. We advise verifying the</span><span class="se">\</span>
<span class="s2">                          integrity of your POTCAR files.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">symbol</span><span class="p">),</span>
                          <span class="n">UnknownPotcarWarning</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">identify_potcar</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;file&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="p">[]:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;POTCAR with symbol </span><span class="si">{}</span><span class="s2"> has metadata that does not match</span><span class="se">\</span>
<span class="s2">                          any VASP POTCAR known to pymatgen. The data in this</span><span class="se">\</span>
<span class="s2">                          POTCAR is known to match the following functionals:</span><span class="se">\</span>
<span class="s2">                          </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">identify_potcar</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;data&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]),</span>
                          <span class="n">UnknownPotcarWarning</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">electron_configuration</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Electronic configuration of the PotcarSingle.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelectrons</span><span class="o">.</span><span class="n">is_integer</span><span class="p">():</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;POTCAR has non-integer charge, &quot;</span>
                <span class="s2">&quot;electron configuration not well-defined.&quot;</span>
            <span class="p">)</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="n">el</span> <span class="o">=</span> <span class="n">Element</span><span class="o">.</span><span class="n">from_Z</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atomic_no</span><span class="p">)</span>
        <span class="n">full_config</span> <span class="o">=</span> <span class="n">el</span><span class="o">.</span><span class="n">full_electronic_structure</span>
        <span class="n">nelect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelectrons</span>
        <span class="n">config</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">while</span> <span class="n">nelect</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">e</span> <span class="o">=</span> <span class="n">full_config</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">config</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
            <span class="n">nelect</span> <span class="o">-=</span> <span class="n">e</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">config</span>

<div class="viewcode-block" id="PotcarSingle.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes PotcarSingle to a file.</span>
<span class="sd">        :param filename: Filename</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">())</span></div>

<div class="viewcode-block" id="PotcarSingle.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="s2">&quot;PotcarSingle&quot;</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads PotcarSingle from file.</span>

<span class="sd">        :param filename: Filename.</span>
<span class="sd">        :return: PotcarSingle.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">match</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(?&lt;=POTCAR\.)(.*)(?=.gz)&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">filename</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">match</span><span class="p">:</span>
            <span class="n">symbol</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">symbol</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">PotcarSingle</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">symbol</span><span class="o">=</span><span class="n">symbol</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;POTCAR contains invalid unicode errors. &quot;</span>
                <span class="s2">&quot;We will attempt to read it by ignoring errors.&quot;</span>
            <span class="p">)</span>
            <span class="kn">import</span> <span class="nn">codecs</span>

            <span class="k">with</span> <span class="n">codecs</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf-8&quot;</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s2">&quot;ignore&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">PotcarSingle</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">symbol</span><span class="o">=</span><span class="n">symbol</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span></div>

<div class="viewcode-block" id="PotcarSingle.from_symbol_and_functional"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.from_symbol_and_functional">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_symbol_and_functional</span><span class="p">(</span><span class="n">symbol</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">functional</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Makes a PotcarSingle from a symbol and functional.</span>

<span class="sd">        :param symbol: Symbol, e.g., Li_sv</span>
<span class="sd">        :param functional: E.g., PBE</span>
<span class="sd">        :return: PotcarSingle</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">functional</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">functional</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_DEFAULT_FUNCTIONAL&quot;</span><span class="p">,</span> <span class="s2">&quot;PBE&quot;</span><span class="p">)</span>
        <span class="n">funcdir</span> <span class="o">=</span> <span class="n">PotcarSingle</span><span class="o">.</span><span class="n">functional_dir</span><span class="p">[</span><span class="n">functional</span><span class="p">]</span>
        <span class="n">d</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_VASP_PSP_DIR&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">d</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;No POTCAR for </span><span class="si">%s</span><span class="s2"> with functional </span><span class="si">%s</span><span class="s2"> found. &quot;</span>
                <span class="s2">&quot;Please set the PMG_VASP_PSP_DIR environment in &quot;</span>
                <span class="s2">&quot;.pmgrc.yaml, or you may need to set &quot;</span>
                <span class="s2">&quot;PMG_DEFAULT_FUNCTIONAL to PBE_52 or PBE_54 if you &quot;</span>
                <span class="s2">&quot;are using newer psps from VASP.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">symbol</span><span class="p">,</span> <span class="n">functional</span><span class="p">)</span>
            <span class="p">)</span>
        <span class="n">paths_to_try</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">funcdir</span><span class="p">,</span> <span class="s2">&quot;POTCAR.</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">symbol</span><span class="p">)),</span>
            <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">funcdir</span><span class="p">,</span> <span class="n">symbol</span><span class="p">,</span> <span class="s2">&quot;POTCAR&quot;</span><span class="p">),</span>
        <span class="p">]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">paths_to_try</span><span class="p">:</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">zpath</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
                <span class="n">psingle</span> <span class="o">=</span> <span class="n">PotcarSingle</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">psingle</span>
        <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span>
            <span class="s2">&quot;You do not have the right POTCAR with functional &quot;</span>
            <span class="o">+</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> and label </span><span class="si">{}</span><span class="s2"> in your VASP_PSP_DIR&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">functional</span><span class="p">,</span> <span class="n">symbol</span><span class="p">)</span>
        <span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">element</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Attempt to return the atomic symbol based on the VRHFIN keyword.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">element</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">[</span><span class="s2">&quot;VRHFIN&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Element</span><span class="p">(</span><span class="n">element</span><span class="p">)</span><span class="o">.</span><span class="n">symbol</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="c1"># VASP incorrectly gives the element symbol for Xe as &quot;X&quot;</span>
            <span class="c1"># Some potentials, e.g., Zr_sv, gives the symbol as r.</span>
            <span class="k">if</span> <span class="n">element</span> <span class="o">==</span> <span class="s2">&quot;X&quot;</span><span class="p">:</span>
                <span class="k">return</span> <span class="s2">&quot;Xe&quot;</span>
            <span class="k">return</span> <span class="n">Element</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">symbol</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;_&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">symbol</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">atomic_no</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Attempt to return the atomic number based on the VRHFIN keyword.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Element</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">element</span><span class="p">)</span><span class="o">.</span><span class="n">Z</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nelectrons</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Number of electrons</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">zval</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">symbol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: The POTCAR symbol, e.g. W_pv</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_symbol</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">potential_type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Type of PSP. E.g., US, PAW, etc.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lultra</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;US&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">lpaw</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;PAW&quot;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;NC&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">functional</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Functional associated with PotcarSingle.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">functional_tags</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LEXCH</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">functional_class</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Functional class associated with PotcarSingle.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">functional_tags</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">LEXCH</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;class&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="PotcarSingle.identify_potcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.identify_potcar">[docs]</a>    <span class="k">def</span> <span class="nf">identify_potcar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;data&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Identify the symbol and compatible functionals associated with this PotcarSingle.</span>

<span class="sd">        This method checks the md5 hash of either the POTCAR data (PotcarSingle.hash)</span>
<span class="sd">        or the entire POTCAR file (PotcarSingle.file_hash) against a database</span>
<span class="sd">        of hashes for POTCARs distributed with VASP 5.4.4.</span>

<span class="sd">        Args:</span>
<span class="sd">            mode (str): &#39;data&#39; or &#39;file&#39;. &#39;data&#39; mode checks the hash of the POTCAR</span>
<span class="sd">                        data itself, while &#39;file&#39; mode checks the hash of the entire</span>
<span class="sd">                        POTCAR file, including metadata.</span>

<span class="sd">        Returns:</span>
<span class="sd">            symbol (List): List of symbols associated with the PotcarSingle</span>
<span class="sd">            potcar_functionals (List): List of potcar functionals associated with</span>
<span class="sd">                                       the PotcarSingle</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Dict to translate the sets in the .json file to the keys used in</span>
        <span class="c1"># DictSet</span>
        <span class="n">mapping_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;potUSPP_GGA&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;PW91_US&quot;</span><span class="p">,</span>
                                        <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;Ultrasoft pseudo potentials</span><span class="se">\</span>
<span class="s2">                                         for LDA and PW91 (dated 2002-08-20 and 2002-04-08,</span><span class="se">\</span>
<span class="s2">                                         respectively). These files are outdated, not</span><span class="se">\</span>
<span class="s2">                                         supported and only distributed as is.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potUSPP_LDA&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA_US&quot;</span><span class="p">,</span>
                                        <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;Ultrasoft pseudo potentials</span><span class="se">\</span>
<span class="s2">                                         for LDA and PW91 (dated 2002-08-20 and 2002-04-08,</span><span class="se">\</span>
<span class="s2">                                         respectively). These files are outdated, not</span><span class="se">\</span>
<span class="s2">                                         supported and only distributed as is.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_GGA&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;PW91&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;The LDA, PW91 and PBE PAW datasets</span><span class="se">\</span>
<span class="s2">                                        (snapshot: 05-05-2010, 19-09-2006 and 06-05-2010,</span><span class="se">\</span>
<span class="s2">                                        respectively). These files are outdated, not</span><span class="se">\</span>
<span class="s2">                                        supported and only distributed as is.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_LDA&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;Perdew-Zunger81&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;The LDA, PW91 and PBE PAW datasets</span><span class="se">\</span>
<span class="s2">                                        (snapshot: 05-05-2010, 19-09-2006 and 06-05-2010,</span><span class="se">\</span>
<span class="s2">                                        respectively). These files are outdated, not</span><span class="se">\</span>
<span class="s2">                                        supported and only distributed as is.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_LDA.52&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA_52&quot;</span><span class="p">,</span>
                                          <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA PAW datasets version 52,</span><span class="se">\</span>
<span class="s2">                                           including the early GW variety (snapshot 19-04-2012).</span><span class="se">\</span>
<span class="s2">                                           When read by VASP these files yield identical results</span><span class="se">\</span>
<span class="s2">                                           as the files distributed in 2012 (&#39;unvie&#39; release).&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_LDA.54&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA_54&quot;</span><span class="p">,</span>
                                          <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;LDA PAW datasets version 54,</span><span class="se">\</span>
<span class="s2">                                           including the GW variety (original release 2015-09-04).</span><span class="se">\</span>
<span class="s2">                                           When read by VASP these files yield identical results as</span><span class="se">\</span>
<span class="s2">                                           the files distributed before.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_PBE&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;The LDA, PW91 and PBE PAW datasets</span><span class="se">\</span>
<span class="s2">                                        (snapshot: 05-05-2010, 19-09-2006 and 06-05-2010,</span><span class="se">\</span>
<span class="s2">                                        respectively). These files are outdated, not</span><span class="se">\</span>
<span class="s2">                                        supported and only distributed as is.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_PBE.52&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE_52&quot;</span><span class="p">,</span>
                                          <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE PAW datasets version 52,</span><span class="se">\</span>
<span class="s2">                                           including early GW variety (snapshot 19-04-2012).</span><span class="se">\</span>
<span class="s2">                                           When read by VASP these files yield identical</span><span class="se">\</span>
<span class="s2">                                           results as the files distributed in 2012.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;potpaw_PBE.54&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE_54&quot;</span><span class="p">,</span>
                                          <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE PAW datasets version 54,</span><span class="se">\</span>
<span class="s2">                                           including the GW variety (original release 2015-09-04).</span><span class="se">\</span>
<span class="s2">                                           When read by VASP these files yield identical results as</span><span class="se">\</span>
<span class="s2">                                           the files distributed before.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;unvie_potpaw.52&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;unvie_LDA_52&quot;</span><span class="p">,</span>
                                            <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;files released previously</span><span class="se">\</span>
<span class="s2">                                             for vasp.5.2 (2012-04) and vasp.5.4 (2015-09-04)</span><span class="se">\</span>
<span class="s2">                                             by univie.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;unvie_potpaw.54&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;unvie_LDA_54&quot;</span><span class="p">,</span>
                                            <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;files released previously</span><span class="se">\</span>
<span class="s2">                                             for vasp.5.2 (2012-04) and vasp.5.4 (2015-09-04)</span><span class="se">\</span>
<span class="s2">                                             by univie.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;unvie_potpaw_PBE.52&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;unvie_PBE_52&quot;</span><span class="p">,</span>
                                                <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;files released previously</span><span class="se">\</span>
<span class="s2">                                                for vasp.5.2 (2012-04) and vasp.5.4 (2015-09-04)</span><span class="se">\</span>
<span class="s2">                                                by univie.&quot;</span><span class="p">},</span>
                        <span class="s1">&#39;unvie_potpaw_PBE.54&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">:</span> <span class="s2">&quot;unvie_PBE_52&quot;</span><span class="p">,</span>
                                                <span class="s2">&quot;vasp_description&quot;</span><span class="p">:</span> <span class="s2">&quot;files released previously</span><span class="se">\</span>
<span class="s2">                                                for vasp.5.2 (2012-04) and vasp.5.4 (2015-09-04)</span><span class="se">\</span>
<span class="s2">                                                by univie.&quot;</span><span class="p">}</span>
                        <span class="p">}</span>

        <span class="n">cwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s1">&#39;data&#39;</span><span class="p">:</span>
            <span class="n">hash_db</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s2">&quot;vasp_potcar_pymatgen_hashes.json&quot;</span><span class="p">))</span>
            <span class="n">potcar_hash</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">hash</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s1">&#39;file&#39;</span><span class="p">:</span>
            <span class="n">hash_db</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">cwd</span><span class="p">,</span> <span class="s2">&quot;vasp_potcar_file_hashes.json&quot;</span><span class="p">))</span>
            <span class="n">potcar_hash</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">file_hash</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Bad &#39;mode&#39; argument. Specify &#39;data&#39; or &#39;file&#39;.&quot;</span><span class="p">)</span>

        <span class="n">identity</span> <span class="o">=</span> <span class="n">hash_db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">potcar_hash</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">identity</span><span class="p">:</span>
            <span class="c1"># convert the potcar_functionals from the .json dict into the functional</span>
            <span class="c1"># keys that pymatgen uses</span>
            <span class="n">potcar_functionals</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">identity</span><span class="p">[</span><span class="s2">&quot;potcar_functionals&quot;</span><span class="p">]:</span>
                <span class="n">potcar_functionals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mapping_dict</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="s2">&quot;pymatgen_key&quot;</span><span class="p">])</span>
            <span class="n">potcar_functionals</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">potcar_functionals</span><span class="p">))</span>

            <span class="k">return</span> <span class="n">potcar_functionals</span><span class="p">,</span> <span class="n">identity</span><span class="p">[</span><span class="s2">&quot;potcar_symbols&quot;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[],</span> <span class="p">[]</span></div>

<div class="viewcode-block" id="PotcarSingle.get_potcar_file_hash"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.get_potcar_file_hash">[docs]</a>    <span class="k">def</span> <span class="nf">get_potcar_file_hash</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Computes a hash of the entire PotcarSingle.</span>

<span class="sd">        This hash corresponds to the md5 hash of the POTCAR file itself.</span>

<span class="sd">        :return: Hash value.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">md5</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span></div>

<div class="viewcode-block" id="PotcarSingle.get_potcar_hash"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.PotcarSingle.get_potcar_hash">[docs]</a>    <span class="k">def</span> <span class="nf">get_potcar_hash</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Computes a md5 hash of the data defining the PotcarSingle.</span>

<span class="sd">        :return: Hash value.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">hash_str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">PSCTR</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">bool</span><span class="p">):</span>
                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">bool</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="nb">list</span><span class="p">)):</span>
                <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">v</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
                        <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="p">(</span><span class="n">Orbital</span><span class="p">,</span> <span class="n">OrbitalDescription</span><span class="p">)):</span>
                        <span class="k">for</span> <span class="n">item_v</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
                            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item_v</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">)):</span>
                                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item_v</span><span class="p">)</span>
                            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item_v</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
                                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{:.3f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item_v</span><span class="p">)</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">hash_str</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item_v</span><span class="p">)</span> <span class="k">if</span> <span class="n">item_v</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">hash_str</span> <span class="o">+=</span> <span class="n">v</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">hash_str</span> <span class="o">=</span> <span class="n">hash_str</span>
        <span class="k">return</span> <span class="n">md5</span><span class="p">(</span><span class="n">hash_str</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegates attributes to keywords. For example, you can use</span>
<span class="sd">        potcarsingle.enmax to get the ENMAX of the POTCAR.</span>

<span class="sd">        For float type properties, they are converted to the correct float. By</span>
<span class="sd">        default, all energies in eV and all length scales are in Angstroms.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">keywords</span><span class="p">[</span><span class="n">a</span><span class="o">.</span><span class="n">upper</span><span class="p">()]</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="n">a</span><span class="p">)</span></div>


<div class="viewcode-block" id="Potcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar">[docs]</a><span class="k">class</span> <span class="nc">Potcar</span><span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for reading and writing POTCAR files for calculations. Consists of a</span>
<span class="sd">    list of PotcarSingle.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">FUNCTIONAL_CHOICES</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">PotcarSingle</span><span class="o">.</span><span class="n">functional_dir</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">functional</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">sym_potcar_map</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            symbols ([str]): Element symbols for POTCAR. This should correspond</span>
<span class="sd">                to the symbols used by VASP. E.g., &quot;Mg&quot;, &quot;Fe_pv&quot;, etc.</span>
<span class="sd">            functional (str): Functional used. To know what functional options</span>
<span class="sd">                there are, use Potcar.FUNCTIONAL_CHOICES. Note that VASP has</span>
<span class="sd">                different versions of the same functional. By default, the old</span>
<span class="sd">                PBE functional is used. If you want the newer ones, use PBE_52 or</span>
<span class="sd">                PBE_54. Note that if you intend to compare your results with the</span>
<span class="sd">                Materials Project, you should use the default setting. You can also</span>
<span class="sd">                override the default by setting PMG_DEFAULT_FUNCTIONAL in your</span>
<span class="sd">                .pmgrc.yaml.</span>
<span class="sd">            sym_potcar_map (dict): Allows a user to specify a specific element</span>
<span class="sd">                symbol to raw POTCAR mapping.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">functional</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">functional</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_DEFAULT_FUNCTIONAL&quot;</span><span class="p">,</span> <span class="s2">&quot;PBE&quot;</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">functional</span> <span class="o">=</span> <span class="n">functional</span>
        <span class="k">if</span> <span class="n">symbols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_symbols</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">functional</span><span class="p">,</span> <span class="n">sym_potcar_map</span><span class="p">)</span>

<div class="viewcode-block" id="Potcar.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict representation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s2">&quot;functional&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">functional</span><span class="p">,</span>
            <span class="s2">&quot;symbols&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">symbols</span><span class="p">,</span>
            <span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
            <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
        <span class="p">}</span></div>

<div class="viewcode-block" id="Potcar.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param d: Dict representation</span>
<span class="sd">        :return: Potcar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Potcar</span><span class="p">(</span><span class="n">symbols</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;symbols&quot;</span><span class="p">],</span> <span class="n">functional</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;functional&quot;</span><span class="p">])</span></div>

<div class="viewcode-block" id="Potcar.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads Potcar from file.</span>

<span class="sd">        :param filename: Filename</span>
<span class="sd">        :return: Potcar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">fdata</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                <span class="s2">&quot;POTCAR contains invalid unicode errors. &quot;</span>
                <span class="s2">&quot;We will attempt to read it by ignoring errors.&quot;</span>
            <span class="p">)</span>
            <span class="kn">import</span> <span class="nn">codecs</span>

            <span class="k">with</span> <span class="n">codecs</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf-8&quot;</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s2">&quot;ignore&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">fdata</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>

        <span class="n">potcar</span> <span class="o">=</span> <span class="n">Potcar</span><span class="p">()</span>
        <span class="n">potcar_strings</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\n?(\s*.*?End of Dataset)&quot;</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">S</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="n">fdata</span><span class="p">)</span>
        <span class="n">functionals</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">potcar_strings</span><span class="p">:</span>
            <span class="n">single</span> <span class="o">=</span> <span class="n">PotcarSingle</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="n">potcar</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">single</span><span class="p">)</span>
            <span class="n">functionals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">single</span><span class="o">.</span><span class="n">functional</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">functionals</span><span class="p">))</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;File contains incompatible functionals!&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">potcar</span><span class="o">.</span><span class="n">functional</span> <span class="o">=</span> <span class="n">functionals</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">potcar</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">potcar</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span> <span class="k">for</span> <span class="n">potcar</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>

<div class="viewcode-block" id="Potcar.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write Potcar to a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): filename to write to.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">())</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the atomic symbols of all the atoms in the POTCAR file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">]</span>

    <span class="nd">@symbols</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_symbols</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">functional</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">functional</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">spec</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the atomic symbols and hash of all the atoms in the POTCAR file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[{</span><span class="s2">&quot;symbol&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="s2">&quot;hash&quot;</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">get_potcar_hash</span><span class="p">()}</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">]</span>

<div class="viewcode-block" id="Potcar.set_symbols"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.Potcar.set_symbols">[docs]</a>    <span class="k">def</span> <span class="nf">set_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">functional</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">sym_potcar_map</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize the POTCAR from a set of symbols. Currently, the POTCARs can</span>
<span class="sd">        be fetched from a location specified in .pmgrc.yaml. Use pmg config</span>
<span class="sd">        to add this setting.</span>

<span class="sd">        Args:</span>
<span class="sd">            symbols ([str]): A list of element symbols</span>
<span class="sd">            functional (str): The functional to use. If None, the setting</span>
<span class="sd">                PMG_DEFAULT_FUNCTIONAL in .pmgrc.yaml is used, or if this is</span>
<span class="sd">                not set, it will default to PBE.</span>
<span class="sd">            sym_potcar_map (dict): A map of symbol:raw POTCAR string. If</span>
<span class="sd">                sym_potcar_map is specified, POTCARs will be generated from</span>
<span class="sd">                the given map data rather than the config file location.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">del</span> <span class="bp">self</span><span class="p">[:]</span>
        <span class="k">if</span> <span class="n">sym_potcar_map</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">PotcarSingle</span><span class="p">(</span><span class="n">sym_potcar_map</span><span class="p">[</span><span class="n">el</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">:</span>
                <span class="n">p</span> <span class="o">=</span> <span class="n">PotcarSingle</span><span class="o">.</span><span class="n">from_symbol_and_functional</span><span class="p">(</span><span class="n">el</span><span class="p">,</span> <span class="n">functional</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="VaspInput"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput">[docs]</a><span class="k">class</span> <span class="nc">VaspInput</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class to contain a set of vasp input objects corresponding to a run.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">incar</span><span class="p">,</span> <span class="n">kpoints</span><span class="p">,</span> <span class="n">poscar</span><span class="p">,</span> <span class="n">potcar</span><span class="p">,</span> <span class="n">optional_files</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            incar: Incar object.</span>
<span class="sd">            kpoints: Kpoints object.</span>
<span class="sd">            poscar: Poscar object.</span>
<span class="sd">            potcar: Potcar object.</span>
<span class="sd">            optional_files: Other input files supplied as a dict of {</span>
<span class="sd">                filename: object}. The object should follow standard pymatgen</span>
<span class="sd">                conventions in implementing a as_dict() and from_dict method.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
            <span class="p">{</span><span class="s2">&quot;INCAR&quot;</span><span class="p">:</span> <span class="n">incar</span><span class="p">,</span> <span class="s2">&quot;KPOINTS&quot;</span><span class="p">:</span> <span class="n">kpoints</span><span class="p">,</span> <span class="s2">&quot;POSCAR&quot;</span><span class="p">:</span> <span class="n">poscar</span><span class="p">,</span> <span class="s2">&quot;POTCAR&quot;</span><span class="p">:</span> <span class="n">potcar</span><span class="p">}</span>
        <span class="p">)</span>
        <span class="k">if</span> <span class="n">optional_files</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">optional_files</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">v</span><span class="p">))</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>

<div class="viewcode-block" id="VaspInput.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="VaspInput.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param d: Dict representation.</span>
<span class="sd">        :return: VaspInput</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dec</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span>
        <span class="n">sub_d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;optional_files&quot;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;INCAR&quot;</span><span class="p">,</span> <span class="s2">&quot;POSCAR&quot;</span><span class="p">,</span> <span class="s2">&quot;POTCAR&quot;</span><span class="p">,</span> <span class="s2">&quot;KPOINTS&quot;</span><span class="p">]:</span>
                <span class="n">sub_d</span><span class="p">[</span><span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">,</span> <span class="s2">&quot;@class&quot;</span><span class="p">]:</span>
                <span class="n">sub_d</span><span class="p">[</span><span class="s2">&quot;optional_files&quot;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">dec</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">sub_d</span><span class="p">)</span></div>

<div class="viewcode-block" id="VaspInput.write_input"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput.write_input">[docs]</a>    <span class="k">def</span> <span class="nf">write_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output_dir</span><span class="o">=</span><span class="s2">&quot;.&quot;</span><span class="p">,</span> <span class="n">make_dir_if_not_present</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write VASP input to a directory.</span>

<span class="sd">        Args:</span>
<span class="sd">            output_dir (str): Directory to write to. Defaults to current</span>
<span class="sd">                directory (&quot;.&quot;).</span>
<span class="sd">            make_dir_if_not_present (bool): Create the directory if not</span>
<span class="sd">                present. Defaults to True.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">make_dir_if_not_present</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">output_dir</span><span class="p">):</span>
            <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">output_dir</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">v</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_dir</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="fm">__str__</span><span class="p">())</span></div>

<div class="viewcode-block" id="VaspInput.from_directory"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput.from_directory">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_directory</span><span class="p">(</span><span class="n">input_dir</span><span class="p">,</span> <span class="n">optional_files</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read in a set of VASP input from a directory. Note that only the</span>
<span class="sd">        standard INCAR, POSCAR, POTCAR and KPOINTS files are read unless</span>
<span class="sd">        optional_filenames is specified.</span>

<span class="sd">        Args:</span>
<span class="sd">            input_dir (str): Directory to read VASP input from.</span>
<span class="sd">            optional_files (dict): Optional files to read in as well as a</span>
<span class="sd">                dict of {filename: Object type}. Object type must have a</span>
<span class="sd">                static method from_file.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sub_d</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">fname</span><span class="p">,</span> <span class="n">ftype</span> <span class="ow">in</span> <span class="p">[</span>
            <span class="p">(</span><span class="s2">&quot;INCAR&quot;</span><span class="p">,</span> <span class="n">Incar</span><span class="p">),</span>
            <span class="p">(</span><span class="s2">&quot;KPOINTS&quot;</span><span class="p">,</span> <span class="n">Kpoints</span><span class="p">),</span>
            <span class="p">(</span><span class="s2">&quot;POSCAR&quot;</span><span class="p">,</span> <span class="n">Poscar</span><span class="p">),</span>
            <span class="p">(</span><span class="s2">&quot;POTCAR&quot;</span><span class="p">,</span> <span class="n">Potcar</span><span class="p">),</span>
        <span class="p">]:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">fullzpath</span> <span class="o">=</span> <span class="n">zpath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">input_dir</span><span class="p">,</span> <span class="n">fname</span><span class="p">))</span>
                <span class="n">sub_d</span><span class="p">[</span><span class="n">fname</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">ftype</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">fullzpath</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>  <span class="c1"># handle the case where there is no KPOINTS file</span>
                <span class="n">sub_d</span><span class="p">[</span><span class="n">fname</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">pass</span>

        <span class="n">sub_d</span><span class="p">[</span><span class="s2">&quot;optional_files&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">optional_files</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">fname</span><span class="p">,</span> <span class="n">ftype</span> <span class="ow">in</span> <span class="n">optional_files</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">sub_d</span><span class="p">[</span><span class="s2">&quot;optional_files&quot;</span><span class="p">][</span><span class="n">fname</span><span class="p">]</span> <span class="o">=</span> <span class="n">ftype</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span>
                    <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">input_dir</span><span class="p">,</span> <span class="n">fname</span><span class="p">)</span>
                <span class="p">)</span>
        <span class="k">return</span> <span class="n">VaspInput</span><span class="p">(</span><span class="o">**</span><span class="n">sub_d</span><span class="p">)</span></div>

<div class="viewcode-block" id="VaspInput.run_vasp"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.inputs.html#pymatgen.io.vasp.inputs.VaspInput.run_vasp">[docs]</a>    <span class="k">def</span> <span class="nf">run_vasp</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">run_dir</span><span class="p">:</span> <span class="n">PathLike</span> <span class="o">=</span> <span class="s2">&quot;.&quot;</span><span class="p">,</span>
        <span class="n">vasp_cmd</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">output_file</span><span class="p">:</span> <span class="n">PathLike</span> <span class="o">=</span> <span class="s2">&quot;vasp.out&quot;</span><span class="p">,</span>
        <span class="n">err_file</span><span class="p">:</span> <span class="n">PathLike</span> <span class="o">=</span> <span class="s2">&quot;vasp.err&quot;</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write input files and run VASP.</span>

<span class="sd">        :param run_dir: Where to write input files and do the run.</span>
<span class="sd">        :param vasp_cmd: Args to be supplied to run VASP. Otherwise, the</span>
<span class="sd">            PMG_VASP_EXE in .pmgrc.yaml is used.</span>
<span class="sd">        :param output_file: File to write output.</span>
<span class="sd">        :param err_file: File to write err.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_input</span><span class="p">(</span><span class="n">output_dir</span><span class="o">=</span><span class="n">run_dir</span><span class="p">)</span>
        <span class="n">vasp_cmd</span> <span class="o">=</span> <span class="n">vasp_cmd</span> <span class="ow">or</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_VASP_EXE&quot;</span><span class="p">)</span>
        <span class="n">vasp_cmd</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expandvars</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">vasp_cmd</span><span class="p">]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">vasp_cmd</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span>
                <span class="s2">&quot;You need to supply vasp_cmd or set the PMG_VASP_EXE in .pmgrc.yaml to run VASP.&quot;</span>
            <span class="p">)</span>
        <span class="k">with</span> <span class="n">cd</span><span class="p">(</span><span class="n">run_dir</span><span class="p">):</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">output_file</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f_std</span><span class="p">,</span> <span class="nb">open</span><span class="p">(</span>
                <span class="n">err_file</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">,</span> <span class="n">buffering</span><span class="o">=</span><span class="mi">1</span>
            <span class="p">)</span> <span class="k">as</span> <span class="n">f_err</span><span class="p">:</span>
                <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">(</span><span class="n">vasp_cmd</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">f_std</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">f_err</span><span class="p">)</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.vasp.inputs</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>